P
Paul Lalli
I ran across this bizarreness while cleaning up someone else's old
code. A short-but-complete script to demonstrate:
#!/usr/bin/perl
use strict;
use warnings;
use Data:
umper;
my %hash;
%hash->{alpha} = 'one';
%hash->{beta} = 'two';
print Dumper(\%hash);
__END__
$VAR1 = {
'beta' => 'two',
'alpha' => 'one'
};
Why does this work? I cannot seem to find any reference to this
alternate hash syntax of using the % sigil and an arrow to access the
values of a plain hash. I made cursory examinations of perldata and
perlref, but nothing jumped out at me.
Interestingly, running this through -MO=Deparse gives the following
output:
my %hash;
$hash{'alpha'} = 'one';
$hash{'beta'} = 'two';
print Dumper(\%hash);
which seems to suggest that the interpeter is allowing %hash->{foo} to
be syntactic sugar for $hash{foo}.
Does anyone know of a reason for this, or of a documentation that
mentions it?
(This is perl, v5.6.1 built for sun4-solaris)
Thank you,
Paul Lalli
code. A short-but-complete script to demonstrate:
#!/usr/bin/perl
use strict;
use warnings;
use Data:
my %hash;
%hash->{alpha} = 'one';
%hash->{beta} = 'two';
print Dumper(\%hash);
__END__
$VAR1 = {
'beta' => 'two',
'alpha' => 'one'
};
Why does this work? I cannot seem to find any reference to this
alternate hash syntax of using the % sigil and an arrow to access the
values of a plain hash. I made cursory examinations of perldata and
perlref, but nothing jumped out at me.
Interestingly, running this through -MO=Deparse gives the following
output:
my %hash;
$hash{'alpha'} = 'one';
$hash{'beta'} = 'two';
print Dumper(\%hash);
which seems to suggest that the interpeter is allowing %hash->{foo} to
be syntactic sugar for $hash{foo}.
Does anyone know of a reason for this, or of a documentation that
mentions it?
(This is perl, v5.6.1 built for sun4-solaris)
Thank you,
Paul Lalli