user-pic

fishy

Subscribe to feed Recent Actions from fishy

  • Aristotle commented on How each drove me crazy

    Actually this is a case where each could be fine, because the loop body is not making any calls to other code that could be messing with the hash’s iterator. He just has to reset the iterator every time he wants to start over:

    sub test_it {
        my $entry = shift;
        keys %regex; # reset iterator
        while( my($type, $regex) = each %regex) {
            return 1 if $entry =~ /$regex/;
        }
        return 0;
    }

    Of course since he doesn’t use the keys in this example, it’s a pointless exercise to use each rather than values.…

Subscribe to feed Responses to Comments from fishy

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.