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
2
votes
2 answers

Can I rename a hash key inside another hash in Perl?

I have a hash of a hash (HoH) that I got from using select_allhashref on a mysql query. The format is perfect for what I want and I have two other HoH by similar means. I want to eventually merge these HoH together and the only problem (I think) I…
dgBP
  • 1,681
  • 6
  • 27
  • 42
2
votes
1 answer

How to print a hash of hashes [of hashes]* as CSV in perl

I want to print a hash of hashes of hashes (with an indefinable depth) as CSV. Imagine that I have a structure of foos, bars, cars, ... where the keys of the deepest hash are pointing to a numeric scalar. I want to print this structure to look like…
Turbokiwi
  • 1,288
  • 10
  • 15
2
votes
1 answer

Combining hashes for an ordered set

An accepted way of combining two hashes from different objects is to use XOR. This makes sense, but as mentioned in the second comment by Thomas Pornin in the below post, XOR is commutative, which means that if you hash each element in a set and…
Trevor Sundberg
  • 1,584
  • 1
  • 14
  • 25
1
vote
2 answers

How do I implement Hash#all? for multidimensional hashes?

Given that I have these hashes: h1 = {"a" => { "b" => 1, "c" => {"d" => 2, "e" => 3} } } h2 = {"a" => { "b" => 1, "c" => nil } } And I want these results: h1.multi_all? # true h2.multi_all? # false How would I implement the multi_all method?
Marek Příhoda
  • 11,108
  • 3
  • 39
  • 53
1
vote
1 answer

How to add a line to multi dimensional hash?

I'm quite new to ruby and I'm blocking on this simple issue: I have the following hash: theData"=>{"586"=>{"status"=>"0"}, "585"=>{"status"=>"0"}} I would like to add a line "current_editor" at each level, to get the following…
ndemoreau
  • 3,849
  • 4
  • 43
  • 55
1
vote
5 answers

Perl - Hash of hashes - is the only option to use "eval" to access variable length key-sequences? {k[0]}=>{k[1]}=>

I am going to keep my question high level, because that is me, that is my style, and that is what I need answer for. I have a multi-level hash to work with (hash of hashes). I also have algorithms that give me a sequence of keys in @key (to various…
1
vote
1 answer

Submitting multiple table entries from a single form submission in rails

I'm trying to make an attendance sheet for my fishing club meetings which shows all the active members and allows you to put a checkbox next to their name, to record if they attended the meeting for a specific tournament. I created a "Meeting"…
railsnoob
  • 51
  • 5
1
vote
3 answers

Going through a Hash of Hash in Perl?

When I try to deference the stored reference (which is set up in the extract Tripwire/get Data subroutines) and convert it back to a hash(in the Compare subroutine), ie %hash = %{$DataHash{$key}};, and I try to print the keys. I run into these…
Shahab
  • 1,977
  • 6
  • 24
  • 28
1
vote
0 answers

How to upload to redis a python's dict of dicts ? (dataframe --> redis)

I have to upload on redis a pandas's dataframe with a column as unique key(timestamp). To do this, I've created a dict in python like this: dict0 = {1431036000: {'col1': '08-05-2015', 'col2': 1.934, 'col3': 905.0} , 1431122400: {'col1':…
1
vote
0 answers

How to interpret (hash reference) results of perl AI::Classifier::Text::FileLearner;

I am trying my own perl "AI hello world" and having a hard time understanding the results of AI::Classifier::Text::FileLearner; I believe I have gone astray in iterating through the hash references. #!/usr/bin/perl use utf8; use strict; use…
gatorreina
  • 864
  • 5
  • 14
1
vote
1 answer

Using each and multiple if statements in Ruby

I first want to apologize because I am not sure if it will make complete sense but I want to provide you with as much context as possible. I working on a lesson that is trying to teach me iterating over hashes and nested hashes. I have been working…
1
vote
2 answers

Perl: push character to hash of array

I am calculating log-odds scores of sequences and returning the motif (small section of sequence) that gives the maximum score. I have code that calculates the maximum score for each sequence in my file, and I am having trouble storing the motif…
William
  • 39
  • 7
1
vote
1 answer

Perl dynamic hash of hash errors

I am looping over a query and returning results. I am trying to add a hash to another hashes. But running into trouble. my %users_data; while($sth->fetch) { $mygroup => { 'fname' => $fname, 'lname' => $lname, …
user3525290
  • 1,557
  • 2
  • 20
  • 47
1
vote
3 answers

Combination of two columns from text file and finding count with reference to third column in Perl

I am trying to read the in.txt file and generate an output file out.txt Using Perl. I tried with Hashes but not getting exact output. Is there a way to do this in Perl. Combination of two columns and providing comments on the basis of third…
user9259206
1
vote
1 answer

How can I extract the list of redirect titles from MediaWiki::API in Perl?

I'm trying to use the MediaWiki API to get all redirects from a certain Wikipedia title and I think i'm almost there but I get lost in the complex data structure of hashes and arrays. How can I extract the list of redirect titles? In the example I…
Sonya
  • 13
  • 2