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.


In reply to Re: finding subroutine dependencies? by jakobi
in thread finding subroutine dependencies? by Anonymous Monk

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!
  • 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, details, 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, summary, 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.