References and Nested Data
Nested Lookup
Nested references let a program group related values inside larger data structures.
Nested Lookup
nested_lookup.pl
use strict;
use warnings;
my $user = ;
my $profiles = {
ana => { city => "Oslo", points => 4 },
ben => { city => "Lima", points => 7 },
};
my $profile = $profiles->{$user};
my $city = $profile ? $profile->{city} : "none";
my $points = $profile ? $profile->{points} : 0;
print "user=$user\n";
print "city=$city\n";
print "points=$points\n";
use strict;
use warnings;
my $user = ;
my $profiles = {
ana => { city => "Oslo", points => 4 },
ben => { city => "Lima", points => 7 },
};
my $profile = $profiles->{$user};
my $city = $profile ? $profile->{city} : "none";
my $points = $profile ? $profile->{points} : 0;
print "user=$user\n";
print "city=$city\n";
print "points=$points\n";
use strict;
use warnings;
my $user = ;
my $profiles = {
ana => { city => "Oslo", points => 4 },
ben => { city => "Lima", points => 7 },
};
my $profile = $profiles->{$user};
my $city = $profile ? $profile->{city} : "none";
my $points = $profile ? $profile->{points} : 0;
print "user=$user\n";
print "city=$city\n";
print "points=$points\n";
nested data
Nested data stores one structure inside another structure.