Just another Perl shrine | |
PerlMonks |
Re: Back to Remedial Perl for Me: map{} functionby dchetlin (Friar) |
on Dec 16, 2000 at 01:33 UTC ( [id://46938]=note: print w/replies, xml ) | Need Help?? |
A note on efficiency:
`map EXPR, LIST' is in general quite a bit faster than `map BLOCK LIST', so you should probably try to use EXPRs rather than BLOCKs whenever possible in a map. For instance, here are your first examples recoded as EXPRs: my @adjusted_array = map $_ * 10, @array; my %hash = map split /-/, @array; Why is it faster? Using the BLOCK introduces a new scope, which adds some extra ops and time to start and finish. BLOCKs do give you extra power and flexibility, but try to use them only when necessary. -dlc
In Section
Seekers of Perl Wisdom
|
|