Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a hash of hashes in Perl?

I am new to Perl. I need to define a data structure in Perl that looks like this:

  city 1 -> street 1 - [ name , no of house , senior people ]
            street 2 - [ name , no of house , senior people ]


  city 2 -> street 1 - [ name , no of house , senior people ]
            street 2 - [ name , no of house , senior people ]

How can I acheive this?

like image 824
Sam Avatar asked Dec 30 '22 17:12

Sam


1 Answers

Here is an another example using a hash reference:

my $data = {
    city1 => {
        street1 => ['name', 'house no', 'senior people'],
        street2 => ['name','house no','senior people'],
    },
    city2 => {
        street1 => etc...
        ...
    }
};

You then can access the data the following way:

$data->{'city1'}{'street1'}[0];

Or:

my @street_data = @{$data->{'city1'}{'street1'}};
print @street_data;
like image 130
Logan Avatar answered Jan 01 '23 17:01

Logan