Skip to content

Instantly share code, notes, and snippets.

@Grinnz
Created December 20, 2017 19:23
Show Gist options
  • Save Grinnz/12deb2e4568415e33bd58ea3a27190c1 to your computer and use it in GitHub Desktop.
Save Grinnz/12deb2e4568415e33bd58ea3a27190c1 to your computer and use it in GitHub Desktop.
perlbugs
The 'each' function documentation is missing some information.
1. When called in scalar context in a while loop, the condition is wrapped
implicitly in a 'defined' check, much like with 'readline'.
e.g. `while (my $key = each %hash) { ... }` becomes
`while (defined(my $key = each %hash)) { ... }`, and
`while (each %hash) { ... }` becomes `while (defined($_ = each %hash)) { ... }`
(on 5.18+)
2. The iterator is not only shared and reset by calling 'keys' or 'values', but
also by other calls to 'each' on the same hash or array, and by accessing the
hash in list context (such as for assignment to another structure, or passing
to a function) - this last one only applies to hashes, not arrays.
When the warning "Scalar value @arrayname[0] better written as $arrayname[0]"
is triggered (any time an array slice is used with only one element), this results
in an error if the array's name starts with 'inf'. Code to reproduce:
use warnings;
my @infasdf;
my @x = @infasdf[0];
1
Error from above code (since 5.22): Cannot printf Inf with 'c' at (IRC) line 3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment