in reply to "return" to break out of a loop

Hanging loop? In mid-air?
return 1 if grep { $check_type eq $_ } @$enums;

Replies are listed 'Best First'.
Re^2: "return" to break out of a loop
by mscharrer (Hermit) on May 13, 2008 at 14:56 UTC
    Very short but not very efficient because the implicit loop is not aborted at the first successful match. Because grep is returning the number of successful matches in scalar context all list elements are getting checked.
    More efficient would be:
    use List::MoreUtils; return 1 if any { $check_type eq $_ } @$enums;
Re^2: "return" to break out of a loop
by weedom (Acolyte) on May 13, 2008 at 14:41 UTC
    meh. Figure of speech :) Cheers WeeDom