k_manimuthu has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have two reference A and B. Ref B is the part of ref A. I am trying to iterate A and check ref B is the part of ref A. Below I place the code which i tried. I am expecting your suggestion to compare the two reference in perl way.
Thanks
use Data::Dumper; my $part = { 'c' => {}, 'func' => [] }; my $main = { 'a' => { 'b' => { 'c' => {}, ### equals to $part hash reference 'func' => [] }, 'func' => [ 'd', 'e' ] } }; walk ($main); sub walk(){ my ($item, $path) = @_; if (ref $item eq 'ARRAY') { foreach (@$item) { walk($_, $path); } ### Need to change the condition/logic here... if ($item eq $main) { print "\nExpected data match here ... ", Dumper $part; } } elsif (ref $item eq 'HASH') { foreach (sort keys %$item) { push @$path, $_; walk($item->{$_}, $path); pop @$path; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: compare two reference in perlway
by Eily (Monsignor) on Oct 19, 2015 at 12:14 UTC | |
|
Re: compare two reference in perlway
by mr_ron (Deacon) on Oct 19, 2015 at 14:15 UTC | |
|
Re: compare two references in the Perl way
by Athanasius (Archbishop) on Oct 19, 2015 at 14:16 UTC | |
by k_manimuthu (Monk) on Oct 20, 2015 at 12:57 UTC | |
|
Re: compare two reference in perlway
by stevieb (Canon) on Oct 19, 2015 at 14:09 UTC | |
|
Re: compare two reference in perlway
by GotToBTru (Prior) on Oct 19, 2015 at 13:02 UTC |