in reply to printf and variables

That's an odd thing to do, but it will work if you seperate all the array elements with newlines and say, printf split /\n/, $newarray;.

It will work better if you use a real array,

my @newarray = ('Hello there %3d %5.1f\n'); push @newarray, 123, $pi; printf @newarray;

I absorbed the constant greeting into the format string.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: printf and variables
by Tanktalus (Canon) on Feb 14, 2005 at 03:49 UTC

    This is close to how I quite often do this very thing:

    my $format = "Hello there %3d!"; my @data = (123); if (defined $pi) # if we've calculated pi ... { $format .= " %5.1f"; push @data, $pi; } printf "$format\n", @data;

    Very useful to be able to do this. The above example specifically doesn't seem too useful, but the overall idea is quite useful. At least to me.