http://www.perlmonks.org?node_id=943316

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

my $a = 1; .. my $b = func1($a); .. sub t{ my ($c) = @_; } t(func2($b));

Since Parse::Perl::Independant can parse Perl itself,is it possible to know that $c is first converted from $a and then converted from $b programatically(which is obvious for human)?

If yes,any advice?

Replies are listed 'Best First'.
Re: Static analysis using PPI
by Corion (Patriarch) on Dec 13, 2011 at 12:37 UTC

    Yes - look at type inference. For a language like Perl, real type inference and/or dataflow analysis will be limited, because eval can be used to overwrite call sequences in various places, as can glob assignment. But for a class of programs that don't do this, it is in theory possible.

Re: Static analysis using PPI
by bluescreen (Friar) on Dec 13, 2011 at 12:48 UTC

    Any static analysis over Perl code is not reliable Perl Cannot Be Parsed: A Formal Proof, in simple cases like this you might be able to trace the origins of a variable but as long as you attempt the same thing over more complex code you will get into trouble because the Perl parser adapts to the run time environment.

Re: Static analysis using PPI
by Anonymous Monk on Dec 13, 2011 at 13:35 UTC