more useful options | |
PerlMonks |
Re^2: A more elegant way to filter a nested hash?by shmem (Chancellor) |
on May 31, 2018 at 10:15 UTC ( [id://1215534]=note: print w/replies, xml ) | Need Help?? |
map can't handle recursion. Of course you can have a map block inside a function, and recurse into that from inside the map block:
which btw is the for loop of the OP rewritten in terms of map/grep. update: a terse version which eliminates shifting @_ and working directly on the arguments (which aren't altered by the function):
Now that's arguably micro-optimized and far less readable (11 lines) than the OP's code (18 lines) imho. More elegant? Perhaps for those who prefer nested ?: statements for simple expressions over if/else blocks... update 2: B::Concise shows identical optrees (execpt line numbers) for the "for" and "map/grep" solutions.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|