Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: substituting values in an array

by tobyink (Canon)
on Jun 18, 2013 at 23:01 UTC ( [id://1039688]=note: print w/replies, xml ) Need Help??


in reply to Re^2: substituting values in an array
in thread substituting values in an array

In this case, the golf is not just for leisure. You'd have to dig out the XS to write a faster solution. On a large array, it's about twice as fast as using map, and about 50% faster than using (admittedly somewhat more readable) for and if blocks.

Also quite fast (though just a teeny bit slower) would be:

$_ = ($_ > 200) ? 200 : $_ for @array;

... though that might degrade quite badly on a tied array as it performs unnecessary extra FETCH and STORE operations.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1039688]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-03-28 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found