"be consistent" | |
PerlMonks |
Re: List Comprehensionsby eyepopslikeamosquito (Archbishop) |
on Oct 16, 2014 at 20:07 UTC ( [id://1104107]=note: print w/replies, xml ) | Need Help?? |
From your question, I am assuming you are an experienced Python programmer, but new to Perl. If you're looking for something similar to Python list comprehensions in Perl, start by mastering the basic Perl built-ins: foreach, map and grep. As LanX has pointed out, map is the right fit for your specific example. Effective Perl Programming has a nice item "Use foreach, map and grep as appropriate", which provides a handy summary of when to use foreach, map and grep:
If you are interested in functional style programming in Perl, once you've mastered these basics, move on to the Perl core List::Util module. After that, CPAN List::MoreUtils. Choosing "good" modules from CPAN is a bit of a dark art. Remember, CPAN is a "commons" with a very low barrier of entry ... so it is full both of gems, and utter rubbish. Before adding a dependency to some random third-party CPAN module, I suggest you check some basic things, to get a feel for how good the module is, like the module rating, CPAN Testers results, change log, test suite, reputable author responsive to bug reports, reported bug list, META.yml/json, pre-reqs, license, kwalitee, and so on, then perhaps google for the module to get a feel for how widely used it is and what folks think of it. For List::Comprehensions, we see:
References Added Later
In Section
Seekers of Perl Wisdom
|
|