***** infoCopter.com/perl *****
HashesUsing Arrays and Hashes
Using arrays and hashes in Perl is easy. Complexity begins when you
continue to work with references to these data types (Find some examples below). Nested Hashes in Perl
#!/usr/bin/perl -w
use strict;
my %myhash = (
"image" => {
"version" => "" ,
"name" => "DSCN4757" ,
"type" => "jpg" ,
"raw_width" => "" ,
"raw_height" => "" ,
"width" => "" ,
"height" => "" ,
"resizedName" => "DSCN4757.sized" ,
} ,
"thumbnail" => {
"version" => "" ,
"name" => "DSCN4757.thumb" ,
"type" => "jpg" ,
"raw_width" => "" ,
"raw_height" => "" ,
"width" => "" ,
"height" => "" ,
"caption" => "DSCN4757" ,
} ,
"itemCaptureDate" => {
"hours" => "21" ,
"minutes" => "52" ,
"seconds" => "59" ,
"mday" => "12" ,
"mon" => "06" ,
"year" => "2003" ,
"uploadDate" => "" ,
"clicks" => "" ,
} ,
"highlight" => {}
);
print "---> ", $myhash{'image'}->{'resizedName'}, "\n";
Playing with hashes
my $categ = &CATEG();
print $categ->{'fookey'}[0]; # prints out 'aa'
sub CATEG () {
my @array1 = qw ( aa bb cc );
my @array2 = qw ( ddd eee fff );
my %hash = (
fookey => \@array1 ,
barkey => \@array2
);
\%hash;
}
|