I was just asking myself exactly that question. Turns out grep requires lvalues, but sort doesn't.
>perl -MO=Concise -e"@b = grep f, @h{@a}" ... a <@> hslice lKM ->b ... >perl -MO=Concise -e"@b = sort @h{@a}" ... a <@> hslice lK ->b ...
Notice the "M" for "Modifiable" in the former.
So that begs the question: Why does grep require lvalues? The difference is:
>perl -e"@a = grep { $_='!'; 0 } @h{qw(i j)};" >perl -e"@a = sort { $a='!'; 0 } @h{qw(i j)};" Modification of a read-only value attempted at -e line 1.
But as far as I can tell, there is no good reason.
In reply to Re^3: Accidentally creating hash elements with grep { defined } on a hash slice
by ikegami
in thread Accidentally creating hash elements with grep { defined } on a hash slice
by ferment
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |