in reply to Loops and variables?
Reading this question in the context of having read Why SprintF? it occurs to me that you're talking about using sprintf to create a string that you then store in a scalar variable. ...as in my $variable = sprintf ..... (where '......' represents the rest of the parameter list). Ok, that's been covered in the previous question. So now on to the current question; can sprintf be used to store formatted data into in array so that as you loop you're able to iterate over this array of sprintf-formatted data? Yes. Here are a couple ways:
# Here's one using 'push': my @array; push @array, sprintf "%2d", $info; push @array, sprintf "%3f", $moreinfo; # Here's another way: my @array; $array[0] = sprintf "%2d", $info; $array[1] = sprintf "%2s", $moreinfo; # And now you can iterate over the array: foreach my $item ( @array ) { print $item, "\n"; }
Dave
|
|---|