Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Back to Remedial Perl for Me: map{} function

by dchetlin (Friar)
on Dec 16, 2000 at 01:33 UTC ( #46938=note: print w/replies, xml ) Need Help??


in reply to Back to Remedial Perl for Me: map{} function

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

Replies are listed 'Best First'.
(tye)Re: Back to Remedial Perl for Me: map{} function
by tye (Sage) on Dec 18, 2000 at 23:54 UTC

    Why is it faster?

    Because the optimizer is "broken". (:

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://46938]
help
Chatterbox?
[Discipulus]: choroba i'm considering to add some connection checking to your CB tk program: something like..
[Discipulus]: i got also a parser error, but once
[KurtZ]: Code Tags
[KurtZ]: ?
[choroba]: <code>...</code>
[choroba]: Discipulus: Yes, all get calls should be wrapped in a Try::Tiny
[choroba]: you can just create a ticket :)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-07-24 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (348 votes). Check out past polls.