Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have got my code working so that if the id is present it prints the correct information. However, when I print the values not in the hash, it just prints out all values again ( so in my printed list i get duplicates if a value is present in the hash).
How can I alter my code to print each id only once? Should the elsif bit not pick up everything not in the hash?
Thanks!
for (my $i=0; $i<@ids; $i++) { my $q; while ( my ($key, $value) = each(%hash) ) { #print "$key =>$value\n"; if ($ids[$i] eq $key) { print "$key => $value => $extra[$i]\n"; } #if ($ids[$i] ne $key) { elsif ($ids[$i] ne $key) { $q = "$ids[$i]\t $extra[$i]\n"; } } # PROBLEM IS HERE: IT IS PRINTING ONE OF EACH VALUE, NOT JUST +THOSE THAT AREN'T IN THE HASH print "$q"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching for values in hashes
by blazar (Canon) on Aug 05, 2005 at 09:51 UTC | |
|
Re: searching for values in hashes
by aukjan (Friar) on Aug 05, 2005 at 09:32 UTC | |
|
Re: searching for values in hashes
by inman (Curate) on Aug 05, 2005 at 10:23 UTC | |
by aukjan (Friar) on Aug 05, 2005 at 11:08 UTC |