Update: It's the eval as roger implicitly pointed out in his reply as well. Time to be explicit. From man perlfunc on
exists
Given an expression that specifies a hash element or array ele-
ment, returns true if the specified element in the hash or
array has ever been initialized, even if the corresponding
value is undefined. The element is not autovivified if it
doesn't exist.
You are autovifying.
You can see this by modifying your code as such.. (use Data::Dumper)
.
.
.
print "----\n";
print Dumper $data;
my $ref = qq|\$data->{$k}$path|;
print "String: $ref\n";
if (my $val = eval($ref)) {
push @results, ref($val) ? $val : eval "\\$ref";
}
if (exists $data->{$k}) {
print Dumper $data;
push @results, rec_data($path, $data->{$k});
.
.
.
Your eval is creating the a-formentioned structure. You may wanna break down your search structure in a different way.
Here's the output from above. You are creating a circular reference.
$VAR1 = {
'foo' => {
'baz' => 'baz',
'bar' => 'bar'
},
'bar' => {
'baz' => 'baz'
}
};
String: $data->{foo}->{foo}->{bar}
$VAR1 = {
'foo' => {
'foo' => {},
'baz' => 'baz',
'bar' => 'bar'
},
'bar' => {
'baz' => 'baz'
}
};
Play that funky music white boy..
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.