Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

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

Hi,there! I want to extract all the function call chains with specific length in source C codes. For example:

f1 calls (f2) f2 calls (f3,f4) f3 calls nothing f4 calls f5 f5 calls nothing

So f1->f2->f4->f5 is one of the function call chains and the length is 4. If I want to extract all the function call chains with length 3, then the results should be:

f1->f2->f3 f1->f2->f4 f2->f4->f5

The source codes are big and I have gotten all the function call information like above, i.e., f1 calls f2 and saved it in a hash of array. The keys are the caller function names and the value arrays are the callee function names. For the example above, the data structure is:

key value f1 f2 f2 f3,f4 f3 f4 f5 f5

I tended to use recursion, but was stuck, pls help! The code snippet is:

my %calls; #has all the function call information my $length = 3; #the length of function chains my @chain_store; #array of array, to save the chains while (($key, $value) = each %calls) { my @chain = (); push @chain, $key; get_chains($value, \@chain); } sub get_chains { my $value = shift; my $chain_ref = shift; my @chain = @{$chain_ref}; foreach my $val @{$value} { push @chain, $val; my $is_present = 1; for (my $count = 0; $count < $length; $count++) { if (exist($calls{$val})) { get_chains($calls{$val}) } else { $is_present = 0; last; } } if ($is_present) { push @chain_store, @chain; } } }

In reply to extract the function call chains of specific length by dwslovedh

Title:
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!
  • 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (11)
    As of 2015-07-07 07:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (87 votes), past polls