azheid has asked for the wisdom of the Perl Monks concerning the following question:
Alright, I do not have any formal training in computer science, so bear with me please. I use perl code in my job to do complex sorts and data mining. I have a job which I think is best handled with recursion, yet I have never really used this technique in perl, so I am getting lots of errors. What I have is a tab delimited file with three columns.
Basically, the first column gives the name of a network element, the second column gives a related network element, and the third column gives how the two are related. The only options for the third column are activate or inhibit. I want to systematically inhibit all network objects(one at a time) and output all the affected objects. The tab delimited file is called useful_dat.tab.
The recursive code that I have is as follows,my @activated; my @inhibited; my $object=test_element; &inhibited_rec($object); print "@activated\n"; print "@inhibited\n"; sub inhibited_rec{ my @a=`awk '\$1 ~ /$_[0]/' useful_dat.tab |cut -f 2,3|sort|uniq`; foreach (@a){ my @b=split(/\t/,$_); if($b[1] eq 'Activation'){ } else{ push (@activated,$b[0]); &activated_rec($b[0]); } } } sub activated_rec{ my @a=`awk '\$1 ~ /$_[0]/' useful_dat.tab |cut -f 2,3|sort|uniq`: foreach (@a){ my @b=split(/\t/,$_); if($b[1] eq 'Activation'){ push (@activated,$b[0]); &activated_rec($b[0]); } else{ push (@inhibited,$b[0]); &inhibited_rec($b[0]); } } }
Some of the details of the code are not included here for clarity. The errors I get involve the variable declarations @a,@b,@activated,@inhibited. Can you please help me figure out how to do this correctly? Or if what I want to do is not possible/very hard in perl, please let me know.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Recursion
by toolic (Bishop) on Sep 26, 2011 at 18:06 UTC | |
|
Re: Perl Recursion
by jwkrahn (Abbot) on Sep 27, 2011 at 00:00 UTC | |
|
Re: Perl Recursion
by zentara (Cardinal) on Sep 26, 2011 at 17:59 UTC | |
|
Re: Perl Recursion
by Limbic~Region (Chancellor) on Sep 26, 2011 at 18:18 UTC | |
|
Re: Perl Recursion
by azheid (Sexton) on Sep 27, 2011 at 22:15 UTC | |
|
Re: Perl Recursion
by azheid (Sexton) on Sep 27, 2011 at 20:07 UTC | |
by toolic (Bishop) on Sep 27, 2011 at 20:24 UTC | |
by azheid (Sexton) on Sep 27, 2011 at 21:28 UTC | |
by aaron_baugher (Curate) on Sep 27, 2011 at 22:33 UTC | |
by azheid (Sexton) on Sep 28, 2011 at 02:10 UTC |