-
-
Save dstu/4489529 to your computer and use it in GitHub Desktop.
Is this a bug in Perl?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Data::Dumper; | |
my $things = { foo => 'bar' }; | |
foreach my $word (qw(foo baz bar quux)) { | |
my $count = grep { defined } $things->{$word}; | |
print "$count\n"; | |
} | |
# $things now has entries for foo, bar, baz and quux | |
# tested on: | |
# perl 5, version 14, subversion 1 (v5.14.1) built for x86_64-linux | |
# perl 5, version 14, subversion 2 (v5.14.2) built for cygwin-thread-multi-64int (with 7 registered patches) | |
# perl, v5.8.8 built for x86_64-linux-thread-multi | |
print Dumper($things); | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, it's not a bug. It's Perl's autovivification doing funny things.