SkipHuffman has asked for the wisdom of the Perl Monks concerning the following question:
Ok, then next question. My situation is that I have a set of data that I would like to access both in an array, and in a hash. Basically the fields have both an ordinal reference, and a named reference. Is there a way to link a data set to both a hash and an array.
Lets say this is my array.
my @array=(Bob, Smith, 1234 Main St, Anytown, 20500);
Or this is my hash.
my %hash=( firstname => Bob, lastname => Smith, address => 1234 Main St, town => AnyTown, zip => 20500);
I can access the information from either one.
print "His name is $array[0] $array[1]\n;
or
print "His name is $hash[firstname] $hash[lastname]\n;
But if I change one the other will, of course, not change.
$array(0)="Robert" print "His name is $hash[firstname] $hash[lastname]\n; #wrong result
Is there a way to tie these two data structures together?
Thank you,
Skip
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Link a hash and an array
by kappa (Chaplain) on Mar 11, 2004 at 20:02 UTC | |
by SkipHuffman (Monk) on Mar 11, 2004 at 20:25 UTC | |
by revdiablo (Prior) on Mar 11, 2004 at 22:54 UTC | |
by SkipHuffman (Monk) on Mar 12, 2004 at 15:45 UTC | |
by SkipHuffman (Monk) on Mar 12, 2004 at 16:23 UTC | |
by revdiablo (Prior) on Mar 13, 2004 at 00:01 UTC | |
by QM (Parson) on Mar 11, 2004 at 21:30 UTC | |
by SkipHuffman (Monk) on Mar 12, 2004 at 15:52 UTC | |
by QM (Parson) on Mar 12, 2004 at 16:35 UTC | |
| |
|
Re: Link a hash and an array
by Vautrin (Hermit) on Mar 11, 2004 at 19:50 UTC | |
|
Re: Link a hash and an array
by bart (Canon) on Mar 11, 2004 at 22:34 UTC | |
|
Re: Link a hash and an array
by Fletch (Bishop) on Mar 11, 2004 at 19:39 UTC |