Front page | perl.beginners |
Postings from February 2002
RE: To create a hash of lists
Thread Previous
|
Thread Next
From:
William.Crain
Date:
February 22, 2002 11:04
Subject:
RE: To create a hash of lists
Message ID:
C5D1F8729F14D511AC3B0220484037D00251AD44@vexwrst02.hurlburt.af.mil
Thanks for the quick and excellent response. I quoted your answer for the
benefit of others. Perl's syntax to work with references is giving me a few
"growing pains" I suppose, though I'm not opposed to working with it once I
get it through my head what is required to make Perl understand what I want.
I did want to add one additional comment to your response however:
>push() requires an array. $foo{bar} is a scalar. @{ $foo{bar} } is
>an array.
>>push($printQueue{A}, 'This is the first line in A');
>>push($printQueue{A}, 'This is the second line in A');
>>push($printQueue{A}, 'This is the third line in A');
>>push($printQueue{A}, 'This is the fourth line in A');
>>push($printQueue{A}, 'This is the fifth line in A');
> push @{ $printQueue{A} }, ...;
>You could just declare your hash as
> my %printQueue = (
> A => [ 'first', 'second', ... ],
> B => [ ... ],
> C => [ ... ],
> );
>Then, to loop over the array references, use
> foreach my $text (@{ $printQueue{$key} }) { ... }
While you are correct, I could define the hash per your example. The
implementation I am working on requires the hash be built dynamically during
execution. I have a file that contains approx. 12000 mapping enumerations
for different types of simulation entities. My script sorts the list of
enumerations, culls where appropriate, and then produces output based on
entity types. The code you helped me with allows me to toss individual
enumerations into "bins" for queued output.
Thanks again.
Will
Thread Previous
|
Thread Next