Consider this simple program. Can you explain why the output is different after uncommenting the first two lines? What is happening with my hash with use strict
? How to fix the program to work with use strict
?
echo -e "key1\nkey2\nkey3" | perl -lne '
#use strict; use warnings;
#my %hash;
BEGIN {
$hash{'key3'} = "value";
}
chomp;
if ($hash{$_}) {
print "$_ matched";
} else {
print "$_ unmatched ";
}
'
Output:
key1 unmatched
key2 unmatched
key3 matched