If I understand you correctly, you are starting with a 2-D array (a flat table) such that in each row of 6 columns (0-5): column 0 is meaningless, columns 1-3 combine to make up a primary key, and columns 4 and 5 are the data of interest for each primary key.
If all rows are unique in terms of the tuples formed by columns 1-3, then you really only need a simple hash, using the concatenation of these three fields as the hash key -- e.g., building on Zaxo's example:
my %table; while (<DATA>) { chomp; my @line = split /,/; my $key = join ",", @line[1..3]; if ( exists( $table{$key} )) { warn "oops -- duplicate key $key... is there a problem with th +at?\n"; next; # just in case there's a problem with that } $table{$key} = join ",", @line[4,5]; } # later on, if you really need the individual columns from the # hash key or the hash value, just use "split /,/" as needed # <update> # note that you can easily search for groups of hash keys: my @root23keys = sort grep /^23,/, keys %table; my @r23p34keys = sort grep /^23,34,/, keys %table; # and so on... </update> __DATA__ 1,2,3,4,100,A 10,20,30,40,200,B 11,21,31,41,300,C 12,22,32,42,400,D 13,23,33,43,500,E 13,23,33,53,600,F 13,23,33,63,700,G 13,23,34,73,800,H 13,23,34,83,900,I 13,24,35,93,1000,J 13,24,36,103,1100,K
In reply to Re: Hashes
by graff
in thread Hashes
by flemi_p
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |