Perl Monk, Perl Meditation | |
PerlMonks |
Re: Help tightening up a subroutine pleaseby gaal (Parson) |
on Jan 23, 2007 at 18:25 UTC ( [id://596132]=note: print w/replies, xml ) | Need Help?? |
First, grep goes over the whole list. If you only need to stop at the first successful match, don't use it. You can use List::Util::first instead.
Other than that, just a blitz look.
This can be written simply as
These may not always be true, but they autovivify an element so *will* be true the second time over you test them with the same key.
If the array is big, you'd do much better just updating a reference to it rather than the above, as you are copying all the elements. Avoiding globals wherever you can is generally a good idea... Update: Most of my points contained mistakes: see below for corrections by kyle++ and BrowserUk++. That'd teach me to post when tired. The advice against globals is probably sound though. :-)
In Section
Seekers of Perl Wisdom
|
|