k_manimuthu has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I am trying to create dynamic references in a recursion function. Below I place code which I try, and it return '{}' only. How to get the initial level reference in else part?
use Data::Dumper; sub insert { my ($ref, $head, @tail) = @_; return unless ( @tail ); if ( @tail and $head ne 'break') { insert( \%{$ref->{$head}}, @tail +) } else { # Here $ref gives '{}' value only. # How to get values of previous head values (ie. f1,f2,f3) print "\n==>", Dumper $ref; # More commands . . . #insert( \%{$ref->{f1}}, @tail ) } } my %hash; while (<DATA>) { chomp and insert \%hash, split( '/', $_ ) ; } print "\nDump\n", Dumper %hash; __DATA__ f1/f2/f3/f4/break/f1/f2/f5/break/f1/f2/f6
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamically create the hash reference
by choroba (Cardinal) on Oct 07, 2015 at 11:09 UTC | |
by k_manimuthu (Monk) on Oct 07, 2015 at 12:29 UTC | |
|
Re: Dynamically create the hash reference
by Discipulus (Canon) on Oct 07, 2015 at 10:31 UTC |