R
rhorizon74
In the code below the print val statement actually creates an key 'ABC'
in the hash if it does not exist ( i wanted to print the value of the
0th element in an array , the reference to which is stored in a hash
with key 'ABC').
Why should a print create a new key, shouldnt it just print undefined,
and not create any new key.
Thank you
Code:
use strict;
use Data:umper;
&main();
sub main
{
my %a;
my $aref = \%a;
print "val: @{$aref->{ABC}}[0]\n";
print Dumper($aref)."\n";
}
Output:
val:
$VAR1 = {
'ABC' => []
};
in the hash if it does not exist ( i wanted to print the value of the
0th element in an array , the reference to which is stored in a hash
with key 'ABC').
Why should a print create a new key, shouldnt it just print undefined,
and not create any new key.
Thank you
Code:
use strict;
use Data:umper;
&main();
sub main
{
my %a;
my $aref = \%a;
print "val: @{$aref->{ABC}}[0]\n";
print Dumper($aref)."\n";
}
Output:
val:
$VAR1 = {
'ABC' => []
};