stallion has asked for the wisdom of the Perl Monks concerning the following question:

hi monks, is there any way to do a call tree analysis using perl?

For eg: A c code function tree display -- audit -- bass elucent -- audit -- check main -- display -- elucent -- audit -- check

In the above audit,bass,display,elucent,main,check are functions

The output should be like this main display audit main display bass main elucent audit main elucent check main audit main check

Im extracting the function names and im having all the function names in an array..And the above function tree will be present in a .txt file.I have to open the .txt file and check for the word (main) which will be default in every conditions and i have to extract ansd write it to an excel sheet.Im a newbie and i just know to open and extract tags using regex from perl..help out monks...

Replies are listed 'Best First'.
Re: call tree analysis using perl
by BrowserUk (Patriarch) on Feb 15, 2012 at 06:39 UTC

    Take a look at Devel::CallTree.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: call tree analysis using perl
by oko1 (Deacon) on Feb 15, 2012 at 07:07 UTC

    Given how fragile and experimental Devel::Calltree is reported to be, and assuming that your data isn't any more complex than what you're showing (large assumption, I know), you could try unwrapping them yourself.

    #!/usr/bin/perl -w use warnings; use strict; my ($tag, %list); while (<DATA>){ next unless /./; if (/^(\w+)/){ $tag = $1; next; } if (/^-- (\w+)/){ push @{$list{$tag}}, $1; } } for my $type (@{$list{main}}){ if ($list{$type}){ for (@{$list{$type}}){ print "main $type $_\n"; } } else { print "main $type\n"; } } __END__ display -- audit -- bass elucent -- audit -- check main -- display -- elucent -- audit -- check

    Output:

    main display audit main display bass main elucent audit main elucent check main audit main check
    -- 
    I hate storms, but calms undermine my spirits.
     -- Bernard Moitessier, "The Long Way"

      Hi oko1 , wonderful dude, I tried the above snippet and it works perfect. but i got a doubt , i tried expanding the function names and still i got only three functions at a time..

      display -- audit -- bass elucent -- audit -- check main -- display -- elucent -- audit -- check audit -- hi_oko1 Output: So the new output should be like this: main display audit hi_oko1 main display bass main elucent audit hi_oko1 main elucent check main audit But still im getting the same o/p:- main display audit main display bass main elucent audit main elucent check main audit hi_oko1

      Hi okol thank u for the response but im getting error msgs

      Name "main::Data" used only once readline() on unopened filehandle DATA

        As there is no Data in that script, I suppose you wrote

        while (<Data>){

        This is not the same as while (<DATA>){ because Perl is case-sensitive.