> What I am looking for (and I think it was hinted in a couple 
> emails) is a way to store 2 pieces of data that both have the 
> same key.  This can be accomplished a number of ways, I guess 
> it comes down to me wondering which is the 'perl' way.  And 
> if you cant tell, I am a new perl convert.

Jason,

Sounds like you want a Hash of Arrays.  (It's A Perl way, but not
necessarily THE Perl way.)  Take a look at this code:

-------->8-------- code --------8<--------
#!perl
use strict;
use warnings;

my %hash;

# In the next five lines, note the use of @{ } to typecast
# the hash value as an array
push @{$hash{key1}}, 'value1';
push @{$hash{key1}}, 'value2';
push @{$hash{key2}}, 'value3';
push @{$hash{key2}}, 'value4';
push @{$hash{key1}}, 'value5';

for my $key (sort keys %hash) {
    print "$key\n";
    # Typecasting again in the next line...
    for my $val (sort @{$hash{$key}}) {
        print "\t$val\n";
    }
}
-------->8-------- code --------8<--------

You might also want to just search for the topic "Hash of Arrays".

Chris


LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be 
privileged. It is intended for the addressee(s) only. Access to this E-mail by 
anyone else is unauthorized. If you are not an addressee, any disclosure or 
copying of the contents of this E-mail or any action taken (or not taken) in 
reliance on it is unauthorized and may be unlawful. If you are not an 
addressee, please inform the sender immediately.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to