in reply to Re: map() abuse or child with a chainsaw
in thread map() abuse or child with a chainsaw

If I think of future readers of my code I'll write:
map shift(@ARGV), qw(two times);
...or (best of all)...
shift(@ARGV); shift(@ARGV);

But this guy I wrote about, should only be allowed to use straight foreach loops from now on :=E (I'm a little emotive right now, excuse me). At least he won't be able to abuse arrayref constructor for plain old parens.

Replies are listed 'Best First'.
(jeffa) 3Re: map() abuse or child with a chainsaw
by jeffa (Bishop) on May 13, 2002 at 14:39 UTC
    Just for sheer TIMTOWTDI:
    @ARGV = @ARGV[2..$#ARGV]; # or for the paran paranoid: @ARGV = (@ARGV)[(2..$#ARGV)];
    ... but i don't like copying the ARGV array back to itself. More readable might be:
    my $discard1 = shift; my $discard2 = shift;
    Out of curiosity, why would one even want to discard the first two arguments like that anyway? Seems like a bad idea in the first place.

    Hmmmm ... sounds like time to pull out one of the Getopt modules to me. ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      Why store the results from the two shift's in variables if the intention is to discard the values?

      shift;shift; # Should do it


      Everything went worng, just as foreseen.

      I admire you, guys :) Correctly identifying this very needed refactoring by seeing shifting of @ARGV is long beyond my abilities :)) Yes, this utility has home-grown option processing.
Re: Re: Re: map() abuse or child with a chainsaw
by demerphq (Chancellor) on May 13, 2002 at 15:55 UTC
    map shift(@ARGV), qw(two times)
    Well, no dont do that.

    :-)

    A very good hint is that you are using map in void context. Thats dumb. (no offense to obfuscators at large ;-). Map is _meant_ to return a set of values, its not meant to be used as a for loop. (In fact my personal belief is that map() and grep() are sorely sorely misnamed. They should be called apply() and filter(), but thats another flame-war iykwim)

    I would say that your second choice is preferred, or possibly

    shift @argv for (1,2);
    But map in void context? No thanks.

    Oh and of course, using Getopt would be a good idea too. (jeffa++)

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.