in reply to Re: Re: sprintf and for loop weirds???
in thread sprintf and for loop weirds???

Or even more robustly with ...

for my $n ($[..$#a) { ... }

For the rare possibility where the first index of arrays may be non-zero as a result of some other strange code obfuscation. :-)

Update : push(@b, sprintf("%.2f", $_)) foreach @a; as suggested by larsen may be nicer and much prettier, but hey! I like obfuscated code :-)

 

Ooohhh, Rob no beer function well without!

Replies are listed 'Best First'.
Re: Re: Re: Re: sprintf and for loop weirds???
by blakem (Monsignor) on Nov 04, 2001 at 16:26 UTC
    Looks like the perfect place for map.
    my @b = map {sprintf("%.2f",$_)} @a;

    Oh, you said obfuscated.... hows this for a first step down obfuscated lane:

    my @b = split' ',sprintf" %.2f"x@a,@a;
    one more step, and I'm done:
    s;;sprintf" %.2f"x@a,@a;e;my@b=split;

    -Blake

      Yes, but you still use sprintf ...

      my@b=map{eval{$_=int$_*10**2;s;(..)$;\.$1;;return$_}}@a;

       

      Ooohhh, Rob no beer function well without!