<?xml version="1.0" encoding="windows-1252"?>
<node id="443660" title="Re: Recursively walk a hash to get to an element" created="2005-03-30 21:00:01" updated="2005-04-07 03:26:20">
<type id="11">
note</type>
<author id="439528">
tlm</author>
<data>
<field name="doctext">
&lt;p&gt;There's an typo in the code; the code block in the &lt;code&gt;reduce&lt;/code&gt; statement should be
&lt;code&gt;
{ \($$a-&gt;{$b}) }
&lt;/code&gt;
Also, when I tried the code as given (after fixing the above typo), I got the error:
&lt;code&gt;
% perl rec_walk.pl
Can't call method "List::Util::reduce" on unblessed reference at rec_walk.pl line 9.
&lt;/code&gt;
Here's the full code of the script that caused that error:
&lt;code&gt;
use strict;
my %myhash;
$myhash{bedrock}{flintstone}{fred} = 3;

my $ref = pointer_to_element(\%myhash, qw(bedrock flintstone fred));

sub pointer_to_element {
  require List::Util;
  return List::Util::reduce { \($$a-&gt;{$b}) } \shift, @_;
}
&lt;/code&gt;
I couldn't figure out why the error, so I switched the code to
&lt;code&gt;
use List::Util 'reduce';
sub pointer_to_element {
  return reduce { \($$a-&gt;{$b}) } \shift, @_;
}
&lt;/code&gt;
and it worked great.  Tres cool.&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-439528"&gt;
&lt;p&gt;&lt;small&gt;the lowliest monk&lt;/small&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;
</field>
<field name="root_node">
443584</field>
<field name="parent_node">
443584</field>
</data>
</node>
