Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How might I handle a special tree?

by vitoco (Hermit)
on Dec 08, 2014 at 22:01 UTC ( [id://1109647]=note: print w/replies, xml ) Need Help??


in reply to How might I handle a special tree?

With the inserted placeholder in the first position of every array as a grouping item, the traverse subroutune looks like this:

my @xx = ['A',1,['B',2,3,4],5,['C',6,['D',7,8,9]]]; traverse("", @xx); sub traverse { my $d = $_[0] . "/" . $_[1][0]; for my $i (1 .. @{$_[1]}-1) { if (ref $_[1][$i] eq 'ARRAY') { traverse($d, $_[1][$i]); } else { print $d . "/" . $_[1][$i] . "\n"; } } }

The result is:

/A/1 /A/B/2 /A/B/3 /A/B/4 /A/5 /A/C/6 /A/C/D/7 /A/C/D/8 /A/C/D/9

I tried to manage the route of groups and subgroups with another array, but got this message when trying to add the first items from the second array to the first one:

Can't use string ("A") as an ARRAY ref while "strict refs" in use at t +est.pl line 6

I couldnīt get rid of it. I also tried passing the arguments by reference, but I got many other error mesages on every change I did.

Replies are listed 'Best First'.
Re^2: How might I handle a special tree?
by Anonymous Monk on Dec 09, 2014 at 04:26 UTC
    your mom is a special tree

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1109647]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found