in reply to Re^2: How to right align outputs of stored data in a variable?
in thread How to right align outputs of stored data in a variable?
I like uniformity in the code and probably would have written the OP's code something like this:#!/usr/bin/perl use strict; use warnings; my $textlength=3; my $numlength=1; # on purpose too narrow my $fmt = "%-$textlength".'s '."%$numlength"."d\n"; print "format is:$fmt"; printf $fmt, "a",1; printf $fmt, "abc",123; printf $fmt, "abcdef",12345; __END__ prints: format is:%-3s %1d a 1 abc 123 abcdef 12345
#!/usr/bin/perl use strict; use warnings; use List::Util qw(sum); my ($FreqP, $FreqN, $FreqZ) = map {int rand 41600} 0..2; my $Sum = sum($FreqP, $FreqN, $FreqZ); printf ( "Freq(Z+): %19d\n" , $FreqP) ; printf ( "Freq(Z-): %19d\n" , $FreqN) ; printf ( "Freq(0): %19d\n" , $FreqZ) ; printf ( "Total: %19d\n" , $Sum) ; __END__ Freq(Z+): 11640 Freq(Z-): 3527 Freq(0): 33243 Total: 48410
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to right align outputs of stored data in a variable?
by AnomalousMonk (Archbishop) on Feb 06, 2017 at 05:40 UTC | |
by Marshall (Canon) on Feb 07, 2017 at 20:53 UTC | |
by AnomalousMonk (Archbishop) on Feb 07, 2017 at 22:35 UTC |