in reply to Loops and variables?
The sprintf() function doesn't store anything. It takes in a set of input parameters and returns an output. It's a transformer, not a storehouse. You have to tell it where to store the result.
This means that you could do the following:
my @array_of_unformatted_numbers = ( 2, 5.3, 56.789, ); my @array_of_formatted_numbers = map { sprintf( "%0.2d", $_ ) } @array_of_unformatted_numbers; foreach my $formatted_number ( @array_of_formatted_numbers ) { print "The formatted number is $formatted_number.\n"; }
|
|---|