Linn Htet Aung
Linn Htet Aung

Reputation: 21

Why does Perl assign a hash reference as value for a non-existent key?

I am using Perl5 (revision 24 subversion 1) on linux.

use strict;
use warnings;

my $fruit_colors = {
        'apple' => {'red' => 'good'}
};

print($fruit_colors->{'orange'}); # this prints nothing

print($fruit_colors->{'orange'}{'orange'}); # this prints nothing too

print($fruit_colors->{'orange'}); # but this suddenly prints 'HASH(0x1f63098)'


My question is why does this happen? and how to prevent it from causing unintential consequences.

Upvotes: 0

Views: 61

Answers (0)

Related Questions