Syntactic Confectionery Delight | |
PerlMonks |
Re^4: loop array excluding some elementsby AnomalousMonk (Archbishop) |
on Apr 19, 2018 at 20:58 UTC ( [id://1213193]=note: print w/replies, xml ) | Need Help?? |
Please excuse the long delay of my reply. I will respond to your specific points, but what prompts my reply now is my post regarding a syntactic idiom I've recently seen that perplexes me even more than the use of map under discussion here; more on that programming pearl below. First it is one liner. But Perl has a format-free syntax: any program can be written in one line — at least, up to the limit of the size of the compiler line input buffer. (Update: In fact, I think every modern computer language, even the P-word one, is or can be made format-free.) ... you can add logic you want under these parentheses ... on your one liner with grep you are just doing a print ... But one can add limitless logic within the statement block (the parentheses) of a for-loop: One could even use a meaningfully-named aliasing iterator variable: for my $tt_thingy (@tt) { ... } One could even write it on a single line (please forgive any wraparound): for (@tt) { if ($_ != 0) { do_something_with_non_zero_iterator_variable($_); do_something_else_with_it($_); } do_even_more_stuff($_); etc(); } So why use a map function? The only motive I can see is that one need never write a Perl-style for-loop again, but what's the advantage of that?
But as I say, the immediate prompt for this reply is the post mentioned above. As you see, this discusses the use of grep in a fashion identical to the use of map we've been talking about. Per your example code, one might write Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom
|
|