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
1
vote
2 answers

How to access a multidimensional hash session?

I am using the session method of Ruby on Rails so that I have a session[:user_params] hash like this: password_confirmation: "test" password: test email: test@test.ij I can access that simply using the syntax session[:user_params] in my view…
user502052
  • 14,803
  • 30
  • 109
  • 188
1
vote
1 answer

Building a hash of hashes to determine largest numerical value in ruby

I have a data file that looks like this: FBpp0070000 acyr193594273 acyr 866 FBpp0070000 acyr193577824 acyr 536 FBpp0070000 acyr193693009 acyr 445 FBpp0070000 bomb193605819 bomb 503 FBpp0070000 bomb193676398 bomb 101 FBpp0070001 acyr193618043 acyr…
user511038
  • 25
  • 5
1
vote
1 answer

Perl -> compare same postitions in arrays in a hash of hashes of arrays

I working a on bash script made by a colleague. Since there is no multidimensional data structure in bash, there was lots of workarounds to process the input files. When I saw his script, I thought Perl can handle that much more easily. I did a…
1
vote
4 answers

how does reduce or inject work in this code

Found this on code wars as one of the solutions. Can someone explain to me how "args.reduce(self)" works in this code; the block after makes sense. config = { :files => { :mode => 0x777 }, :name => "config" } class Hash def get_value( default,…
Wolf_Tru
  • 523
  • 7
  • 19
1
vote
2 answers

Trying to access a hash in a constant list of hashes in perl

Okay so this is my current code which works, but I need to access each error hash in a different way in order to be compatible with other parts of the program. Here is my Error list library: Type.pm package ASC::Builder::Error::Type; use strict; …
Paul Russell
  • 179
  • 10
1
vote
2 answers

Multilevel Hash Default Parameters When Accessing Non-Existant Keys as in h[1][1] += 1

I'm trying to create a Hash of Hash-es. The value of the 2nd level hash is an integer defaulted to 0. What I'm trying to do is start with an empty hash of hashes, and then when I add a value if the key doesn't exist, they key should be added with…
John Dibling
  • 99,718
  • 31
  • 186
  • 324
1
vote
2 answers

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

Dereferencing an array reference from a nested Perl hash

I hope I've stated that subject correctly. I have a hash of hashes that I've built from reading a file. The outer hash is groups, then the inner hash is parameters within that group. Each parameter value can either be a scalar or array, and the…
Andy
  • 11
  • 3
1
vote
2 answers

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

how to increment hash of hash in perl

failing to properly populate a HoH using this code: when i run the loop using below: while (my $form = $form_rs->next ()){ my $menu=$form->get_column("fmenu"); my $script=$form->get_column("fscript"); my…
rajeev
  • 1,275
  • 7
  • 27
  • 45
1
vote
1 answer

Storing a hash of hashes in Redis

What's the best way to store an hash in Redis which looks like this: id1->{key1->value1, key2->value2, key3->value3….} , id3->{key1->value1, key2->value2, key3->value3….} …. where key1, key2, key3... is two-letters code of language (en, es, etc),…
Incerteza
  • 32,326
  • 47
  • 154
  • 261
1
vote
4 answers

How to use the sort_by method to sort teams from Win/Loss Data

I'm confused as to how to use the sort_by method. How do I rearrange this: @final_leaderboard = { "Patriots" => {"Win"=>3, "Loss"=>0}, "Broncos" => {"Win"=>1, "Loss"=>1}, "Colts" =>…
Dan Rubio
  • 4,709
  • 10
  • 49
  • 106
1
vote
1 answer

Perl - Hash of Hash - test if entry exists

I have a problem, when I try to find if a entry exists in my Hash of Hash and if it don't exists, Perl create me this entry. Exemple of my code : use warnings; use strict; my %hash; $hash{'key1'}{'subkey1'} = "value1"; if (…
1
vote
1 answer

Filter hash of hashes array to get only certain key & values

Using psd.rb gem to return a hash of the properties of a psd file. However I would like to somehow filter the results down just to the font name. Is there a method that can get the value of keys nested within a certain hash e.g the :font…
Sam Mason
  • 1,037
  • 1
  • 8
  • 29
1
vote
2 answers

Perl: inserting array of arrays in into a array which is a value for a key

I have a need of inserting an array of arrays into an array.And this whole array is a value for a key in a hash.i meant hash should look like this: "one" [ [ 1, 2, [ [ 3, 4 ], [ 5, 6 ] …
user1939168
  • 547
  • 5
  • 20