On Mon, Mar 14, 2005 at 05:32:01PM -0800, Tim Johnson wrote:
> 
> Did you try enumerating the keys of %hash?
> 
> foreach my $outerKey(sort keys %hash){
>    print "$outerKey\n";
>    foreach my $innerKey(sort keys %{$hash{$outerKey}}){
>       print "\t$innerKey\n";
>    }
> }

I guess I have to explain better:

my %hash = ( 
        abcd => {
                a1 => 1,
                a2 => 2,
                a3 => 3
        },

        efgh => {
                b1 => 4,
                b2 => 5,
                b3 => 6
        }
);
 

sub_call (\%hash, 'abcd');

exit 0;



sub sub_call {
        
        my ($hashref, $object) = @_;

        print "Now working on $object using values\n";
        
        foreach my $key (keys %{${$hahsref}{$object}}) {

                print "$key\n";
        }
}

Simple enough right? What I was asking is how can I get the same result 
without passing 'abcd' and a reference to the outter hash, but by passing 
ONLY a reference to the inner hash. Actually the more I think about it the 
more I figure it can't be done, since references are symbolic and don't 
carry information about upper (or technically lower) level structures as the 
outer hash that contains the actual key name... Am I correct? :)
If I am then comes the other question - are references memory hungry? In 
other words do if I pass a ref of the outter hash (which in my case is very 
very large) would I end up with a copy as big just for the sake of running 
each subroutine? If this is the case - I don't like it :)
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to