http://qs321.pair.com?node_id=1215726


in reply to Re^3: A more elegant way to filter a nested hash?
in thread A more elegant way to filter a nested hash?

Excuse me, but what you are calling syntactic sugar, I call grammar!. Actually I find your comment diminishing towards all those fantastic computer linguistics that have been working so hard to incorporate iterative behaviors into the natural language of Perl. Choosing long used idioms over major parts of the grammar is your choice but personally I feel you are staying one step behind. Take Perl 6 for example where they are taking these concepts even a 1000 steps further!

Just doing a bit of googling, finding tons of examples. This one from the perl6 archives is already from 2000:

The ability to take an indexed slice of a hash is desired. This would allow the programmer to pare out several keys and values from hash A into a new hash B, for greatest flexibility. Currently, this is only available through map():

    %other = map { $_ => $sounds->{$_} } qw(lizard duck);

Which could be simplified to:

%other = slice(%$sounds, { qw(lizard duck) }); # or, %other = (%$sounds =~ sl/lizard duck/h); # or, %other = %$sounds->{'lizard', 'duck'}; # or, %other = %{$sounds}{ qw(lizard duck) }; # trad'l

Syntactic sugar? Sure, whatever.

edit: corrected typo, changed last comment.