Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
2)my @a; $a[0] = 5; $a[1] = 2; for(my $n=0;$n < scalar(@a); $n++) { $b[$n] = sprintf("%.2f", $a[$n]; } print "$b[0] : $b[1]\n";
basically the first snippet doesn't set $b[1] it only sets $b[0], is this something weird with sprintf or something dodgey with my for loop?my @a; $a[0] = 5; $a[1] = 2; $b[0] = sprintf("%.2f", $a[0]; $b[1] = sprintf("%.2f", $a[1]; print "$b[0] : $b[1]\n";
cheers
Dave
Edit kudra, 2001-11-04 Corrected markup
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sprintf and for loop weirds???
by Fastolfe (Vicar) on Nov 04, 2001 at 21:16 UTC | |
|
Re: sprintf and for loop weirds???
by rob_au (Abbot) on Nov 04, 2001 at 16:07 UTC | |
by blakem (Monsignor) on Nov 04, 2001 at 16:15 UTC | |
by rob_au (Abbot) on Nov 04, 2001 at 16:20 UTC | |
by blakem (Monsignor) on Nov 04, 2001 at 16:26 UTC | |
by rob_au (Abbot) on Nov 04, 2001 at 17:30 UTC | |
by chipmunk (Parson) on Nov 04, 2001 at 21:01 UTC | |
|
Re: sprintf and for loop weirds???
by larsen (Parson) on Nov 04, 2001 at 16:13 UTC | |
|
Re: sprintf and for loop weirds???
by echo (Pilgrim) on Nov 04, 2001 at 17:17 UTC | |
|
Re: sprintf and for loop weirds???
by Anonymous Monk on Nov 05, 2001 at 18:45 UTC | |
by blakem (Monsignor) on Nov 06, 2001 at 00:01 UTC |