[tpm] fmt string effect on array of values
Tom Legrady
legrady at gmail.com
Sat Jan 8 19:16:05 PST 2011
I'm writing a little demo program for work. I've generating a header
for a table :
Originally I had a set of values and a set of strings of hyphens, but
I thought I should use an array of values, and generate the hyphens
from the list. That way if i rename the fields, the hyphenation will
follow automatically. So I tried:
my @fields = ( q/size N sum avg/ );
printf $fmt, ( @fields );
printf $fmt, map { q{-} x length $_ } @fields;
By the way, $fmt is "%16s %4s %16s %16s\n";
But the %s in the fmt string provides a double-quoted string context
to @fields, so all the values go into the first field and the others
are empty.
size N sum avg
Use of uninitialized value in printf at ./filecount.pl line 133.
Use of uninitialized value in printf at ./filecount.pl line 133.
Use of uninitialized value in printf at ./filecount.pl line 133.
--------------
Additional values outside the array are properly put into the
additional fields, at least in monospace font they look right:
printf $fmt, ( @fields ), 'x', 'y', 'z';
printf $fmt, map { q{-} x length $_ } @fields, 'x', 'y', 'z';
size N sum avg x y z
-------------- - - -
Any ideas on how to partition the array elements among the various
fields, other than reverting to separate strings?
Tom
More information about the toronto-pm
mailing list