in reply to Re^3: Accidentally creating hash elements with grep { defined } on a hash slice
in thread Accidentally creating hash elements with grep { defined } on a hash slice

Why does grep require lvalues?
So you can suprise people with what this does:
perl -e "@in = (1..5); @out = grep { $_++ } @in; print qq{@in}"
But as far as I can tell, there is no good reason.
Oh - a good reason? Sorry, haven't got one of them. Move along please, nothing to see here.

--
.sig : File not found.

  • Comment on Re^4: Accidentally creating hash elements with grep { defined } on a hash slice
  • Download Code

Replies are listed 'Best First'.
Re^5: Accidentally creating hash elements with grep { defined } on a hash slice
by ikegami (Patriarch) on Nov 04, 2008 at 15:21 UTC

    True, but it's a bad example since @in naturally returns lvalues.

    >perl -le" @in = (1..5); @out = sort { $a=$b='!'; 0 } @in; print qq{@i +n}" ! ! ! ! !

    Note the absence of the "M" flag.

    >perl -MO=Concise -le" @in = (1..5); @out = sort { $a=$b='!'; 0 } @in; + print qq{@in}" ... e <1> rv2av[t11] lK/1 ->f ...

    It will affect

    pp_pos - Adds lvalue magic pp_substr - Adds lvalue magic pp_vec - Adds lvalue magic pp_aelem - Extends array pp_aelemfast - Extends array pp_aslice - Extends array pp_helem - Extends hash pp_hslice - Extends hash pp_padsv - No effect as far as I can tell pp_rv2sv - ??? pp_rv2av - ??? pp_rv2gv - ???