Perl: the Markov chain saw | |
PerlMonks |
Re^3: substituting values in an arrayby tobyink (Canon) |
on Jun 18, 2013 at 23:01 UTC ( [id://1039688]=note: print w/replies, xml ) | Need Help?? |
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:
... 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
In Section
Seekers of Perl Wisdom
|
|