• About: I blog about Perl.
  • Commented on Do not use each
    I only hit a problem with each recently (see Using a hash in list context will use the iterator internally so simply assigning the hash you are iterating over to another hash will cause an infinite loop. I now...
Subscribe to feed Recent Actions from martin.j.evans

  • Timm Murray commented on Do not use each

    I've also seen situations where each was called in a loop that short-circuits:

    while( my ($key, $val) = each %hash ) {
        last if $key =~ /foo/;

    Then later on, each is used again without resetting the internal state, even though the programmer expected to iterate over the entire hash. With a hash stored globally (yes, this is bad in itself, but it happens) in a persistent environment like mod_perl, this can even happen across different requests in the same process.

  • Tim Bunce commented on Do not use each

    I wonder if there's some way to make the each op warn if the iterator isn't where it's expected to be.

  • E. Choroba commented on Do not use each

    Unfortunately, glob is similarly broken:

    perl -E 'for my $x (qw(* )) { print "$x: ", scalar glob($x), "\n"}'

  • E. Choroba commented on Do not use each

    Sorry, should have been:

    perl -E 'for my $x (qw(* < >)) { print "$x: ", scalar glob($x), "\n"}'

Subscribe to feed Responses to Comments from martin.j.evans

About is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.