Re: Help with Hash of Hashes
- From: cartercc <cartercc@xxxxxxxxx>
- Date: Tue, 17 Jun 2008 07:18:23 -0700 (PDT)
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
.
- References:
- Help with Hash of Hashes
- From: Kevin Brammer
- Help with Hash of Hashes
- Prev by Date: Re: rt.cpan.org works ok (was: Re: rt.cpan.org, search.cpan.org: why so unuseable?)
- Next by Date: Re: Learning Perl
- Previous by thread: Re: Help with Hash of Hashes
- Next by thread: Re: Help with Hash of Hashes
- Index(es):
Relevant Pages
|