References and Nested Data
Hash References
A hash reference points to a hash, and ->{key} reads one value from it.
Hash References
hash_refs.pl
use strict;
use warnings;
my $key = ;
my $scores_ref = { perl => 92, go => 88 };
my $exists = exists $scores_ref->{$key};
my $value = $exists ? $scores_ref->{$key} : 0;
my $status = $exists ? "found" : "missing";
print "key=$key\n";
print "status=$status\n";
print "value=$value\n";
use strict;
use warnings;
my $key = ;
my $scores_ref = { perl => 92, go => 88 };
my $exists = exists $scores_ref->{$key};
my $value = $exists ? $scores_ref->{$key} : 0;
my $status = $exists ? "found" : "missing";
print "key=$key\n";
print "status=$status\n";
print "value=$value\n";
use strict;
use warnings;
my $key = ;
my $scores_ref = { perl => 92, go => 88 };
my $exists = exists $scores_ref->{$key};
my $value = $exists ? $scores_ref->{$key} : 0;
my $status = $exists ? "found" : "missing";
print "key=$key\n";
print "status=$status\n";
print "value=$value\n";
hash reference
A hash reference is a scalar value that points to a hash.