Running perl 5.12.4 Am getting disparity between result of a function when a hash is assigned within the return statement or beforehand. Easiest example is:
perl -e 'sub s1 {
my @a=qw/b 1 c 2 a 3 a 4/;
my %h=@a;
return %h
}
print "@{[ s1()]}\n"'
c 2 a 4 b 1
perl -e 'sub s1 {
my @a=qw/b 1 c 2 a 3 a 4/;
my %h=@a;
return %h=@a
}
print "@{[ s1()]}\n"'
c 2 c 2 a c
Why does (re)assigning to hash in return statement (2nd example) corrupt the returned hash?
Because of a bug. It appears to have been fixed in 5.14.0. (Present in 5.12.4. Not present in 5.14.0)
Minimal test case:
perl -E"say %h = qw/b 1 c 2 a 3 a 4/"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With