From 8059dc445531b51b7d6e21d88edd59464d5d387f Mon Sep 17 00:00:00 2001 From: Dan Church Date: Tue, 13 Sep 2022 11:50:10 -0500 Subject: [PATCH] Add thousands separator commas to output --- CHANGELOG.md | 1 + simplify_static_dir.pl | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48ff9cb..14592ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. - Limit "Skipped" output to only summary - Omit output of progress bar unless -v flag is present +- Add thousands separator commas to output ## [3.0.0] diff --git a/simplify_static_dir.pl b/simplify_static_dir.pl index db4a243..04e88e0 100755 --- a/simplify_static_dir.pl +++ b/simplify_static_dir.pl @@ -238,8 +238,8 @@ MAIN: { $freed_bytes += $inst->bytes_freed; } - printf STDERR "freed %d bytes (%0.4G %s)\n", - $freed_bytes, + printf STDERR "freed %s bytes (%0.4G %s)\n", + Directory::Simplify::Utils::addcommas($freed_bytes), Directory::Simplify::Utils::hr_size($freed_bytes) if $print_freed or $verbose; } @@ -248,6 +248,18 @@ package Directory::Simplify::Utils; use strict; use warnings; +sub addcommas { + my @added; + foreach my $num (@_) { + # don't split anything after the decimal + my @parts = split /\./, $num; + while ($parts[0] =~ s/(\d)(\d{3}(?:\D|$))/$1,$2/) { + } + push @added, (join '.', @parts); + } + wantarray ? @added : $added[0] +} + sub hr_size { my $sz = shift; my @sizes = qw/ B KB MB GB TB PB EB ZB YB /;