Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have the following pseudo code, and I need to build a hash of unique keys, with arrays of unique values for each key.
This is what I want to end up with:#!/usr/bin/perl -w use strict; my &hash; while (<DATA>) { $hash{$first} = $second; # only grabs the last value } while ((my $key, my $value) = each %construct) { print "The $key is: $value \n"; } _DATA_ 5 25 6 27 5 24 5 23 6 29 6 30 4 22 5 25 6 27 4 22 4 21
The Key is: 5 25 24 23 The Key is: 6 27 29 30 The Key is: 4 22 21
Any suggestions for a routine?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unique keys for multiple values with a Hash
by Ovid (Cardinal) on Jan 14, 2003 at 19:08 UTC | |
by Anonymous Monk on Jan 14, 2003 at 19:37 UTC | |
|
Re: Unique keys for multiple values with a Hash
by gjb (Vicar) on Jan 14, 2003 at 19:02 UTC | |
|
Re: Unique keys for multiple values with a Hash
by Zaxo (Archbishop) on Jan 14, 2003 at 19:09 UTC | |
|
Re: Unique keys for multiple values with a Hash
by tall_man (Parson) on Jan 14, 2003 at 19:12 UTC | |
by Anonymous Monk on Jan 14, 2003 at 19:18 UTC | |
by tall_man (Parson) on Jan 14, 2003 at 19:28 UTC |