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

Data::Diver was already recommended to you by ikegami.

  • Comment on Re: checking if hashref value exists based on a dynamic array

Replies are listed 'Best First'.
Re^2: checking if hashref value exists based on a dynamic array
by jonathan415 (Novice) on Aug 08, 2008 at 06:36 UTC
    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.

      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;
      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.

      Look inside and you'll know