in reply to Re: checking if hashref value exists based on a dynamic array
in thread checking if hashref value exists based on a dynamic array

ikegami, thanks for recommending Data::Diver. I did take a look at it, and it does answer the question. But the problem with modules is that they do the work, and you don't know how they done it. I was more interested in a ways of mapping data structure myself. My first question was actually very different from this one, and I was able to use the concepts of that answer to solve a more complex problem that I had. Basically, I was interested seeing ways of transversing the data structure and how those values relate to each other. If anyone has any other ways of doing it, I'm interested in seeing it.
  • Comment on Re^2: checking if hashref value exists based on a dynamic array

Replies are listed 'Best First'.
Re^3: checking if hashref value exists based on a dynamic array
by ikegami (Patriarch) on Aug 08, 2008 at 07:10 UTC

    But the problem with modules is that they do the work, and you don't know how they done it.

    Probably something along the lines of the following, with error checking added.

    my $p = \$href; $p = \($$p->{$_}) for @keys; $$p = $val;

    Update: Oops, the above is code for setting with autovivification (your other question). Checking if the indexes exist without autovivification could be done using

    my $p = $href; for (@keys) { return 0 if !exists($p->{$_}); $p = $p->{$_}; } return 1;
Re^3: checking if hashref value exists based on a dynamic array
by chromatic (Archbishop) on Aug 08, 2008 at 07:01 UTC
    But the problem with modules is that they do the work, and you don't know how they done it.

    The source code is generally available, and many modern modules include decent test suites.

Re^3: checking if hashref value exists based on a dynamic array
by Anonymous Monk on Aug 08, 2008 at 06:55 UTC
    Look inside and you'll know