in reply to sprintf and for loop weirds???

yup thanks guys, i ended up using map :) works best, i think why it wasn't working is because perls sprintf calls the systems sprintf when dealing with floats
Try this code on for size
$a[0] = 5; $a[1] = 3; $a[3] = 15; for($n = 0; $n < scalar (@a); $n++) { $b[n]=sprintf("%.2f", $a[n]); } print "$b[0]\n"; print "$b[1]\n"; print "$b[2]\n"; print "$b[3]\n";
the output of this is "5.00\n\n\n\n"...

Notice the $a2 is not defined, perhaps something with C's sprintf doesn't like how perl deals with undefined vars???
this is copied and pasted from a shell so there are no sytax probs here :P

cheers
Dave

Replies are listed 'Best First'.
Re: Re: sprintf and for loop weirds???
by blakem (Monsignor) on Nov 06, 2001 at 00:01 UTC