Skip to content

Instantly share code, notes, and snippets.

@anazawa
Created March 28, 2012 06:02
Show Gist options
  • Select an option

  • Save anazawa/2224110 to your computer and use it in GitHub Desktop.

Select an option

Save anazawa/2224110 to your computer and use it in GitHub Desktop.
# while_each_last.pl
use strict;
use warnings;
my %foo = ( foo => 'bar' );
while ( my ( $k, $v ) = each %foo ) {
print "$k: $v\n";
last;
}
# last でループを抜けたため、each %foo の iteration がリセットされていない
while ( my ( $k, $v ) = each %foo ) {
print "$k: $v\n";
last;
}
$ perl -v
This is perl 5, version 12, subversion 3 (v5.12.3) built for darwin-multi-2level
...
$ perl while_each_last.pl
foo: bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment