diff --git a/CHANGES b/CHANGES index b76cc9d..54e0485 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +0.8 (2024-03-11) +* pretty-print large numbers with thousands-separator + 0.7 (2024-02-06) * fixed a regular expression to use \t instead of a literal tab * changed variable named $nm to $netmask diff --git a/README.md b/README.md index ed4d174..4900f4a 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,9 @@ Total counts: Total # of 'exists' directives : 1 Total # of 'include' directives : 7 Total # of ip4 directives : 45 - Total # of ip4 addresses : 870171 + Total # of ip4 addresses : 870,171 Total # of ip6 directives : 11 - Total # of ip6 addresses : 29712752120897178112958136320 + Total # of ip6 addresses : 29,712,752,120,897,178,112,958,136,320 All others: softfail ``` diff --git a/src/spf.pl b/src/spf.pl index 9e5b738..c30095c 100755 --- a/src/spf.pl +++ b/src/spf.pl @@ -14,6 +14,7 @@ use Getopt::Long; Getopt::Long::Configure("bundling"); use Math::BigInt; # Used to show IP counts in full without scientific notation +use POSIX qw(locale_h); use Socket qw(PF_UNSPEC PF_INET PF_INET6 SOCK_STREAM inet_ntoa); use Socket6; @@ -46,7 +47,7 @@ use constant MAXLENGTH => 450; my %OPTS = ( v => 0 ); my $PROGNAME = basename($0); my $RETVAL = 0; -my $VERSION = 0.7; +my $VERSION = 0.8; # The final result in json representation: # { @@ -773,6 +774,16 @@ sub expandSPF($$$$) { } } +sub formatNumber($) { + my ($num) = @_; + my $h = localeconv(); + my $t = $h->{mon_thousands_sep}; + $t //= ','; + + while ($num =~ s/^(-?\d+)(\d\d\d)/$1$t$2/) {}; + return $num; +} + sub getCIDRCount($) { my ($cidr) = @_; @@ -1281,12 +1292,12 @@ sub printCount($$$) { if ($stats{"${ipv}-directives"}) { print " "; print "Total # of $ipv directives : "; - print $stats{"${ipv}-directives"} . "\n"; + print formatNumber($stats{"${ipv}-directives"}) . "\n"; } if ($stats{"${ipv}count"}) { print " "; print "Total # of $ipv addresses : "; - print $stats{"${ipv}count"} . "\n"; + print formatNumber($stats{"${ipv}count"}) . "\n"; } }