nickandrew has asked for the wisdom of the Perl Monks concerning the following question:
O wise perl monks,
please grant me the benefit of your advice:
Investigating a bizarre problem today, I found some anomalous behaviour in perl.
use Data::Dumper qw(Dumper); my $data = { args => '', }; $data->{args}->{stuff} = 'bother'; print Dumper($data); print "The value is ", $data->{args}->{stuff}, "\n";
The script outputs:
$VAR1 = { 'args' => '' }; The value is bother
Now, "$data->{args}" has been initialised to a scalar empty string. Without using "use strict", perl allows code which treats this like a hashref and stores something in it. The stored data (in this case, a hashref with key stuff and value bother) can't be seen by Data::Dumper but can be retrieved in the same way it was stored.
Is this a perl bug? If I "use strict" then my program emits an error.
Is this a language feature? I have checked this behaviour in perl 5.6, 5.8 and 5.10. Is it something to do with symbolic references ala "use strict refs" ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The hidden hashref
by moritz (Cardinal) on May 19, 2010 at 13:10 UTC | |
|
Re: The hidden hashref
by almut (Canon) on May 19, 2010 at 13:39 UTC | |
|
Re: The hidden hashref
by GrandFather (Saint) on May 19, 2010 at 21:33 UTC |