Software >> Development >> Languages >> Perl >>  How to create 2-dimensional hash , example 1

Example 1 ========= my $records = {}; my $newrow = {}; $newrow->{'name'} = "tom"; $newrow->{'tel'} = "123"; $newrow->{'addr'} = "abc"; $records->{'1'} = $newrow; my $newrow = {}; $newrow->{'name'} = "dick"; $newrow->{'tel'} = "456"; $newrow->{'addr'} = "def"; $records->{'2'} = $newrow; my $newrow = {}; $newrow->{'name'} = "harry"; $newrow->{'tel'} = "789"; $newrow->{'addr'} = "ghi"; $records->{'3'} = $newrow; printf "1 : %-10s\t %-10s \t %-10s\n",$records->{'1'}->{'name'},$records->{'1'}->{'tel'},$records->{'1'}->{'addr'}; printf "2 : %-10s\t %-10s \t %-10s\n",$records->{'2'}->{'name'},$records->{'2'}->{'tel'},$records->{'2'}->{'addr'}; printf "3 : %-10s\t %-10s \t %-10s\n",$records->{'3'}->{'name'},$records->{'3'}->{'tel'},$records->{'3'}->{'addr'};