Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi Monks!

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

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]/' |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]/' |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.

In reply to Perl Recursion by azheid

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (3)
    As of 2018-05-21 04:02 GMT
    Find Nodes?
      Voting Booth?