Re: Help with Hash of Hashes



On Jun 17, 12:25 am, Kevin Brammer <kncb...@xxxxxxxxxxxxxxxxxxxx>
wrote:
I'm trying to write what I thought would be a simple script for work. I
can visualize the data structure I need in my head, but coding it is
another story. Basically, I'm parsing a text file which is the output
of a web query. The format is basically:

00-00AAAA
- string,0,0,0,0,0
- string,0,0,0,0,0

I solved an identical probelm with a hash array references. My file
contained open seats in course sections, like this:
BIO-1101 ZA1:20 ZA2:20 ZA3:20
ENG-1101 ZA1:25 ZA2:25

To write, I created a hash of courses (like BIO-1101) with a value
comprised of a reference to an array, and then pushed each section to
the array for each hash.

To read, I iterated through the hash created the courses, then split
the array elements on the colon, then iterated through that, like
this:

my ($crs, $sec)
foreach $crs (sort keys %open_seats)
foreach $sec (sort keys %{open_seats{$crs}})
print "$crs $sec $open_seats{$crs}{$sec}\n"

The data structure looks like this:
BIO-1101 => [ZA1:20, ZA2:20, ZA3:30]

CC
.



Relevant Pages

  • Re: problem with hash & sort array
    ... Then I put the hash into an array with the sort ... The twist is I have to identify the duplicate ... a real data structure, and in the next place I make the exact opposite ...
    (comp.lang.perl.misc)
  • Re: What kind of data type is?
    ... But all objects based on the Objectimplement hash ... > (associative array) data structure, because it appeared to be the most ... we could say that it's a bastard of HTMLCollection. ...
    (comp.lang.javascript)
  • Re: How to count value in a ArrayList
    ... were adding was not already stored in the data structure. ... Doing this with a ArrayList is a lot slower than a hash ... But presumably they use a relatively common technique of having a fixed-sized array of bins that grows as the hash table accumulates items. ... Some implementations use bins that are either arrays or linked lists, while others simply use the next available spot in the hash table. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Whats more efficient, hash or array
    ... > that using hash should be expensive than using the direct-access ... > array. ... then probably an array is not the right data structure. ... you didn't mean efficiency in programming and maintance but efficiency ...
    (comp.lang.perl.misc)
  • Duck Typed Concepts for Ruby (was Re: A use case for an ordered hash)
    ... An Sequencable mixin can be defined that implements all sorts of operations such as append, concat, splice, sort, etc. ... extending an instance of Array with Sorted if the array is known to be sorted. ... Now returning to the thread at hand we can see that the difference between the associative array and hash hierarchies is that the hash hierarchy depends upon Hashable keys. ...
    (comp.lang.ruby)