stevieb has asked for the wisdom of the Perl Monks concerning the following question:
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 ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex critique
by LanX (Saint) on Sep 07, 2018 at 21:25 UTC | |
by LanX (Saint) on Sep 07, 2018 at 23:20 UTC | |
|
Re: Regex critique
by Corion (Patriarch) on Sep 08, 2018 at 06:10 UTC | |
|
Re: Regex critique ( intention? )
by beech (Parson) on Sep 07, 2018 at 21:29 UTC |