So the value of 'myvar' should stay the same, whatever it is, from the first dump to the second dump right? Wrong!
#!/usr/local/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $myvar;
print Dumper($myvar);
if ($myvar->{bleh}) {
$myvar->{bleh} = 'cool';
}
print Dumper($myvar);
Since the variable 'myvar' is not initialized, when you use it as a hash reference, Perl thinks this variable is a hash reference, and converts it to a hash reference! Here's the output of the above code:
The value of this variable has clearly changed without notifying the programmer! Remember to always initialize your variables!
$VAR1 = undef;
$VAR1 = {};
No comments:
Post a Comment