Questions tagged [hash-of-hashes]

A hash-of-hashes is a multi-dimensional hash that contains nested hashes.

A multi-dimensional hash is a flexible, nested structure where hash values are allowed to be other hashes. This data structure is natively supported by languages such as:

  • Perl
  • Python
  • Ruby

and may be simulated by others.

141 questions
0
votes
2 answers

Issues iterating over deeply nested hash of hashes inside an array

So, a quick mockup of my issue can look like this ... `def problem [{ 'Hash1' => { 'Hash_1' => 'abcd', 'Hash_2' => 'abcd', 'Hash_3' => nil, } }, { 'Hash2' => { 'Hash_1' => 'efg', 'Hash_2' =>…
vin_Bin87
  • 318
  • 8
  • 18
0
votes
2 answers

Given a hash of items (also a hash), return a hash that consolidates duplicates and provide counts for each item

I'm working to better understand hashes, and I've come across problems in which I have a collection with duplicate items and I need to return a hash of those items de-duped while adding a key that counts those items. For example... I have a hash of…
jamesvphan
  • 1,825
  • 6
  • 23
  • 30
0
votes
1 answer

How to add a scalar value (string) to an existing hash in Perl

I just want to know what the process is behind merging a value into a hash. I have a hash which has 5 to 6 keys depending on if the error outputs runtime values. The method that takes in the arguments also take an error message string in first,…
Paul Russell
  • 179
  • 10
0
votes
1 answer

How to iterate over an array of hashes which contain instantiated object information in Ruby?

I created a class called Dish, where I then created a number of menu objects, items for a menu containing name and price, the information which was obtained through the initialized method. when calling chickenstew = Dish.new("Chicken Stew",…
sdawes
  • 631
  • 1
  • 7
  • 15
0
votes
2 answers

Perl: Access hash of dynamic depth

I am struggling with accessing/ modifying hashes of unknown (i.e. dynamic) depth. Suppose I am reading in a table of measurements (Length, Width, Height) from a file, then calculating Area and Volume to create a hash like the following: # …
SSilk
  • 2,433
  • 7
  • 29
  • 44
0
votes
1 answer

Unit testing in perl, Receiving hash ref as return expected to return a string from a key in a hash

I am trying to test the output of the following method: package ASC::Builder::Error; sub new { my ($package, $first_param) = (shift, shift); if (ref $first_param eq 'HASH') { my %params = @_; return bless { message =>…
Paul Russell
  • 179
  • 10
0
votes
1 answer

Unit testing an object in Perl. Checking that it contains specific hash values

I have created an error object from an error hash and I'm trying to create unit tests that check the objects contain all the correct keys. ErrorLibrary.pm use constant { CABLING_ERROR => { errorCode => 561, message => "cabling is not…
Paul Russell
  • 179
  • 10
0
votes
1 answer

creating a subroutine in Perl that will take a hash from a hash of hashes as an argument and print out one of the values from that hash

More details: 1st hash: hash of error messages 2nd hash: error message itself (error_name) which contains 3 key values (statusCode, message, params) I am trying to create a method that will take in error_name and print out the message. This is the…
Paul Russell
  • 179
  • 10
0
votes
4 answers

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…
jdamae
  • 3,839
  • 16
  • 58
  • 78
0
votes
1 answer

Parsing a HoAoHoAoHoAoH in Perl

I am new to Perl and have a little idea about hashes. I have a hash of array of hash of array of hash of array of hash (HoAoHoAoHoAoH) as follows. %my_hash = ( key00 => 'value00', key01 => [ { key10 => 'value10', key11 =>…
thefoobarguy
  • 23
  • 1
  • 5
0
votes
2 answers

Perl Hash of Hash

So I am trying to use a Perl HoH and push some values into an array from the HoH. Here is a portion of the code to better explain; my $hoh = ( antenna_included=>{ "1" => '1 MultiBand Antenna', "2" =>'2 Multiband Antennas', "3" =>'1…
nzaleski
  • 433
  • 5
  • 14
0
votes
1 answer

Parse tab delimited file into hash of array

I'm a perl novice attempting to perform the following: 1) Take a user input 2) Match the input with instances of that value from column1 of file 1 and store the corresponding value from the column 2 in a hash, hash of array or hash of hash. (below…
CJ87
  • 35
  • 1
  • 4
0
votes
1 answer

Sort both levels of keys for hash of hashes in perl

I have a code where I need to keep track of some values (that come up at random) at given positions in different categories (and a fairly large number of them; ~40,000), so I thought a hash of hashes would be the best way, with categories as first…
Beemo
  • 3
  • 2
0
votes
3 answers

accessing the highest value in hash of an hash in perl?

so i have a hash of an hash that looks something like this: my %hash = ( 'fruits' => { 'apple' => 34, 'orange' => 30, 'pear' => 45, }, 'chocolates' => { 'snickers' => 35, 'lindt' =>…
0
votes
2 answers

Perl - Printing elements within a hash structure

I have a huge, huge, huge data structure, exactly in the format as shown below from Data::Dumper (though greatly simplified for the purposes of explaining the problem). { Fred => { "Street Name" => ["First Avenue"], …
yonetpkbji
  • 1,019
  • 2
  • 21
  • 35