in reply to Re: basic question:how to print a reversed array from STDIN
in thread basic question:how to print a reversed array from STDIN

I cringe when I see map or grep modify $_.

Replies are listed 'Best First'.
Re^3: basic question:how to print a reversed array from STDIN
by holli (Abbot) on Dec 04, 2008 at 12:53 UTC
    I agree with you in regards to grep, but map? It's sole purpose is the modification of $_.


    holli, /regexed monk/

      No - map returns a new list, so changing $_ makes little sense. Either use a foreach if you want to do an inplace modification of a list or return a fresh list and try to keep away from changing the list alias :)

        Yes, if you take care about the list on the right hand side. But, consider this:
        map { s/^.//; } grep { /^[abc]/ } @somewords;


        holli, /regexed monk/