hash-of-hashes

How can I create a hash of hashes in Perl?

Hi everyone, 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 p...

How do I recursively define a Hash in Ruby from supplied arguments?

This snippet of code populates an @options hash. values is an Array which contains zero or more heterogeneous items. If you invoke populate with arguments that are Hash entries, it uses the value you specify for each entry to assume a default value. def populate(*args) args.each do |a| values = nil if (a.kind_of? Hash) #...

Nested hash defined?()

What's the most concise way to determine if @hash[:key1][:key2] is defined, that does not throw an error if @hash or @hash[:key1] are nil? defined?(@hash[:key1][:key2]) returns True if @hash[:key1] exists (it does not determine whether :key2 is defined) ...

help understanding perl hash

Perl newbie here...I had help with this working perl script with some HASH code and I just need help understanding that code and if it could be written in a way that I would understand the use of HASHES more easily or visually?? In summary the script does a regex to filter on date and the rest of the regex will pull data related to tha...

help printing out hash keys to needed format

I need help printing out data from a hash/hash ref to STDOUT or file with data in a specific order if possible. I have a perl routine that uses hash references like so: #!/usr/local/bin/perl use strict; use warnings; use File::Basename; use Data::Dumper; my %MyItems; my $ARGV ="/var/logdir/server1.log"; my $mon = 'Aug'; my $day = '0...

perl - help with hash and dumping of records

I have a perl script that is only keeping the last set of records for a named set and I have more than one set of records. So its over writing the data in the hash and just keeping the last set. I need help in printing out all the records. Thanks! Here's a copy of my script: #!/usr/local/bin/perl use strict; use warnings; use Data::D...

How do I map (and sort) values from a hash of hashes?

I have a hash of hashes, like so: %hash = ( a => { b => 1, c =>2, d => 3}, a1 => { b => 11, c =>12, d => 13}, a2 => { b => 21, c =>22, d => 23} ) I want to extract the "b" element and put it into an array. Right now, I am looping through the hash to do this, but I think I can improve efficiency slightly by using...