The perldocs say the following about last:
lastcannot be used to exit a block that returns a value such aseval {},sub {}, ordo {}, and should not be used to exit a grep() or map() operation.
Why should it be avoided in a grep() or map()? I’m especially curious about map since it is an alternative to the foreach construct. The docs seem to insist on not doing something without describing the consequences.
First, realise that
grepandmapare transparent tonext,lastandredo, just likeifis.But the docs doesn’t say
lastcannot be used to exitmap, it says it shouldn’t used. It’s not clear what that means.mapandgrep?mapandgrep?I don’t know.
I don’t think it’s #3 because I don’t know of any bad side-effects of using
next,lastandredoto leave amaporgrepcallback.The funny thing, leaving
mapandgrepusing a loop construct doesn’t even warn even though leaving a sub in the same fashion does.