Now that I'm back home, we're getting a bit back to normalcy. Going to stay in one of my cabins tonight (~500 metres from my main house) and do some fishing (rainbow trout today).

While I'm gone, I'm hoping the Monks can chew on a couple of regexes I've got. Essentially, it is part of my Devel::Examine::Subs distribution, and its purpose is to identify subroutine definitions/declarations within a Perl file. Due to PPI, I already know where these things are, but I'm throwing as a challenge whether these regexen could be improved on. I've tried to imagine all scenarios where a sub definition could be on a single or multi-line here.

my $single_line = qr/ sub\s+\w+\s*(?:\(.*?\)\s+)?\{\s*(?!\s*[\S]) | sub\s+\{\s*(?!\s*[\S]) /x; my $multi_line = qr/sub\s+\w+\s*(?![\S])/;

I'd love for regex experts to show me examples of sub def lines that the regexes won't catch, and fixes to them. I'm especially interested in help with fixes to catch signatures and prototypes ;)


In reply to Regex critique by stevieb

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.