Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I would like to be able to sort through both "D" and "E" at the same time ... something along the lines of:$hash{A}{B}{C}{D}{one} = "1"; $hash{A}{B}{C}{D}{two} = "2"; $hash{A}{B}{C}{D}{thr} = "3"; $hash{A}{B}{C}{E}{one} = "4"; $hash{A}{B}{C}{E}{two} = "5"; $hash{A}{B}{C}{E}{thr} = "6";
that is, I want to sort the keys of hash_ref D and E, then use the value of $hash{A}{B}{C}{D}{$key} || $hash{A}{B}{C}{E}{$key} depending on which it came from.foreach my $key (sort {$a cmp $b} keys "D", "E") { print "$hash{$key}"; }
the results that I get from this are:#!/usr/bin/perl -w use strict; my %hash; $hash{A}{B}{C}{D}{one} = "1"; $hash{A}{B}{C}{D}{two} = "2"; $hash{A}{B}{C}{D}{thr} = "3"; $hash{A}{B}{C}{E}{one} = "4"; $hash{A}{B}{C}{E}{two} = "5"; $hash{A}{B}{C}{E}{thr} = "6"; foreach my $key (keys %{$hash{A}{B}{C}{E}}, %{$hash{A}{B}{C}{D}}) { print "$key\n"; }
And even so, I am not sure how to know which hash_ref "$key" is currently coming from.thr one two thr 3 one 1 two 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: working with multiple hash refs
by sauoq (Abbot) on Dec 19, 2002 at 21:10 UTC | |
|
Re: working with multiple hash refs
by tachyon (Chancellor) on Dec 19, 2002 at 21:28 UTC | |
|
Re: working with multiple hash refs
by jdporter (Paladin) on Dec 19, 2002 at 21:41 UTC | |
by sauoq (Abbot) on Dec 19, 2002 at 22:18 UTC | |
by jdporter (Paladin) on Dec 20, 2002 at 01:02 UTC | |
by sauoq (Abbot) on Dec 20, 2002 at 01:23 UTC |