http://www.perlmonks.org?node_id=600788

thenetfreaker has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Algorithmic hash bug.
by shmem (Chancellor) on Feb 19, 2007 at 08:24 UTC
    "without a singl loop"

    Direct hash lookups indeed work without loops.

    So how can i correct my mistake ?

    which mistake? Got some error? Some code, apart from that multilevel hash lookup?

    From what you say I figure you mean

    my $x = $hash{$valueM}{$key};

    because you say "where the mainKey equals $valueM". As you have written that multilevel hash lookup, the string contained in $valueM would be one key in an anonymous hash stored as the value for the key 'mainKey' in the hash %hash. I guess that's different to what you wrote. But how can I know? I know what I mean. Why don't you?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Algorithmic hash bug.
by cdarke (Prior) on Feb 19, 2007 at 13:19 UTC
    If I read your question correctly, it is very simple:
    $x = $hash{$valuem};
    The solution you provided implies: a hash with the key 'mainKey', whose value is a reference to a hash with the key in $valueM, whose value is a reference to a hash with the key 'key'.
Re: Algorithmic hash bug.
by ysth (Canon) on Feb 19, 2007 at 10:20 UTC
    "without a singl loop"
    What are you quoting? A homework assignment?
Re: Algorithmic hash bug.
by pajout (Curate) on Feb 19, 2007 at 15:24 UTC
    I guess that you want something like this:
    use strict; use warnings; my $valueM = 'myvalue'; my $hashref; $$hashref{mainKey}{$valueM}{key} = 'value';

    or
    my %hash; $hash{key} = 'value'; ...