matt me has asked for the wisdom of the Perl Monks concerning the following question:
I have two arrays. I wish one array to become to the keys to a hash, the other array to become the values to the hash. I want $array[5] to be paired in the hash with $arraytwo[5]. The closest I could get was by using a hash slice,
Which set @array to be keys in %hash. I don't know how to set @arraytwo to be values in %hash. Thanksmy %hash; @hash{@array}=%hash;
Update: Ok, thanks very much, the @hash{@array} = @arraytwo; hashslice worked fine. The possibility of duplicates occurs in only array, so I guess I should have that array as the values, to avoid problems.
Edit: BazB added extra code tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Two arrays. One hash.
by Zaxo (Archbishop) on Nov 29, 2003 at 22:19 UTC | |
|
Re: Two arrays. One hash.
by Limbic~Region (Chancellor) on Nov 29, 2003 at 22:25 UTC | |
|
Re: Two arrays. One hash.
by davido (Cardinal) on Nov 29, 2003 at 22:40 UTC | |
by Roger (Parson) on Nov 29, 2003 at 23:47 UTC | |
by jeffa (Bishop) on Nov 30, 2003 at 15:46 UTC | |
|
Re: Two arrays. One hash.
by Aristotle (Chancellor) on Nov 30, 2003 at 18:56 UTC |