Who is this for
This article is for those who want to learn how to use multi-dimensional hashes.
Introduction
Perl hashes are data types that allow you to associate data to a key.%hash = (20030227 => 'Multi-dimensional hashes', 20030113 => 'Introduction to mod_perl', 20021201 => 'The CPAN Module' );
Two-Dimensional Hash
You can however, create multi-dimensional hashes depending on your need.%info = (title=> 'Multi-dimensional hashes', author=> 'Philip Yuson' );
We can then refer to this hash in the first hash item:
%hash2 = (20030227 => \%info);
$ref = $hash2{20030227}; # set $ref to the
# reference pointing to
# %info
$ref->{title}; # get the data on the
# title item of the %info hash.
$hash2{20030227}->{title}; #
$hash2{20030227}{title};
%info1 = (title=> 'Multi-dimensional hashes', author=>'Philip Yuson'); %info2 = (title=> 'Introduction to mod_perl', author=>'Philip Yuson'); %info3 = (title=>'The CPAN Module', author=>'Philip Yuson');%hash3 = (20030227 =>\%info1, 20030113=>\%info2, 20021201=>\%info3);
This is a bit awkward, so to simplify this:
%hash3 = (20030227 => {title=> 'Multi-dimensional hashes', author=>'Philip Yuson'}, 20030113 => {title=> 'Introduction to mod_perl', author=>'Philip Yuson'}, 20021201 => {title=> 'The CPAN Module', author=>'Philip Yuson'} );Multi-Dimensional Hashes
Based on the discussion, multi-dimensional hashes are made up of hashes that
refer to hashes that refer to hashes.
Go To Page: 1