SPUG: extracting functions
Tim Maher/CONSULTIX
tim at consultix-inc.com
Thu Apr 13 16:08:25 CDT 2000
Sounds like a job for Damian Conway's extract_codeblock() function from
the CPAN "Text::Balanced" module:
extract_codeblock attempts to recognize and extract a
balanced bracket delimited substring which may contain
unbalanced brackets inside Perl quotes or quotelike
operations. That is, extract_codeblock is like a
combination of "extract_bracketed" and
"extract_quotelike".
-Tim
(jet-lagged, so take everything I say today with a large dash of salt!)
*========================================================================*
| Tim Maher, PhD Consultix & (206) 781-UNIX/8649 |
| Pacific Software Gurus, Inc Email: tim at consultix-inc.com |
| UNIX/Linux & Perl Training http://www.consultix-inc.com |
| Classes; 5/16: UNIX 5/22: Basic Perl+Modules 6/12: Intermediate Perl |
*========================================================================*
On Thu, Apr 13, 2000 at 01:14:16PM -0700, Todd Wells wrote:
> Hi, I want to write a perl program that will parse my existing perl programs
> and alphabetize the functions.
>
> I think have a pretty good handle on how I can do this conceptually, but I'm
> not sure how I would go about getting all of one function into a string.
>
> I imagine something like this, but I'm not sure how to deal with nested
> curly braces...
>
> $myfunc =~ /(^sub\w+{.+?})/m;
>
> I know this isn't what I want, this would probably grab my first "sub
> whatever {" through the last "}" in the program.
>
> I need it to be able to get all of a function like this...
>
> sub myfunk {
> if ($maybe) {
> # do this
> } else {
> # do that
> }
> }
>
> ...and be smart enough to end at the correct bracket.
>
> Maybe one of you could point me in the right direction?
>
> -Todd
==========================================================
| Tim Maher, Ph.D. Tel/Fax: (206) 781-UNIX |
| SPUG Founder & Leader Email: spug at halcyon.com |
| Seattle Perl Users Group HTTP: www.halcyon.com/spug |
==========================================================
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
Email to majordomo at pm.org: "action" spug-list your_address
More information about the spug-list
mailing list