in reply to finding subroutine dependencies?

One trivial illustration of the problems, even ignoring the works of art created as part of the obfuscated perl contents:
sub craziness_lurks_here{ # do not count } me, I'm in a comment, not a '-ed string warn "a parens }?\n"; print <<EOF; } EOF }

Statical: So counting parens on the cheap w/o full parsing (maybe -> Deparse, B, ...) is a problem. If you've a kind of contract with your script authors (they write what you can match), you could get away with just regex hacking for a partial 70% job (extending /sub\+\w\s+(/ to match trivial sub definitions. Similar with sub uses), maybe enough for your use.

Dynamics: But you still miss (or in general at least cannot determine the sub used in) say sub-references in assignments... but AFAICS this is outside the possibilities of static analysis for both practical and general cases, at least when excluding the most trivial examples (static code validation with theorem provers should still be fairly restricted, even though I didn't follow advances in that area for more than a few years now). Which pretty much closes the circle and leads back to the remarks of my fellow monks above.

Update: on reading the answer below and the regexes I didn't add above with e.g. /\{{3}/, I just remembered that nowadays we can also have perl5 code run within a regex itself, /(?{print "}"})/ I'd assume. Not to mention the older and more traditional while loop replacement:

while(s/\{/\}/gio){$b=~//;some-more-code-here} # vs s/\{/do{some-other-regexes+some-more-code-here;"}"}/egi # (don't use delimeters like s{}{}ige, that way you'd # loose the construct's intended capriciousness :> )

Tasty.

Replies are listed 'Best First'.
Re^2: finding subroutine dependencies?
by Anonymous Monk on Oct 02, 2009 at 00:06 UTC

    So counting parens on the cheap w/o full parsing (maybe -> Deparse, B, ...) is a problem.

    I had resolved this problem by running all code through perltidy -dac first. An additional problem is whether braces might occur with strings. This can be dealt with by reducing all strings to null before running through perltidy. The only other possibility I can think of would be braces appearing with regular expressions, but thus far, I hadn't run into enough occurrences to warrant figuring out a solution yet.

    Thanks everyone for your responses. I'll look more at the CPAN references mentioned earlier later tonight.