My approach, to ensure uniqueness in values, would be to make the values the keys of hash and then transform them into an array reference.
#!/usr/bin/perl -w use strict; use Data::Dumper; my %hash; while (<DATA>) { next unless /[^[:space:]]/; # make sure there's something on the l +ine my ($key,$value) = split; $hash{$key}{$value} = 0; } foreach my $key (keys %hash) { $hash{$key} = [keys %{$hash{$key}}]; } print Dumper \%hash; __DATA__ 5 25 6 27 5 24 5 23 6 29 6 30 4 22 5 25 6 27 4 22 4 21
Update: Everyone seems to want to push the value on an array which doesn't get the "unique values" in the original request.
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
In reply to Re: Unique keys for multiple values with a Hash
by Ovid
in thread Unique keys for multiple values with a Hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |