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

I agree with you in regards to grep, but map? It's sole purpose is the modification of $_.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^4: basic question:how to print a reversed array from STDIN
by Corion (Patriarch) on Dec 04, 2008 at 12:55 UTC

    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/

        Now I also cringe at the map in void context.

        There's also a lack of visual distinction between list generation and list transformation.

        s/^.// for grep { /^[abc]/ } @somewords;