Click here to get back home

Text::Balanced to extract subs?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Text::Balanced to extract subs? ivowel 06-15-2006
Posted by ivowel on June 15, 2006, 10:35 pm
Please log in for more thread options



dear perl users: I want to write a function that extracts "ordinary"
subroutines from perl code. (an equivalent task is extracting all
macros from a latex file.) I am not trying to be too clever. let's
presume I can recognize subs because subs and only subs always start at
the first character of a line and are not anonymous. a sub is followed
by a name and can contain nested expressions.

I can do plain pattern matching to find the first occurance of the
first sub: '^sub [a-zA-Z]+'. but now I am stuck. I need to continue
on with a Text::Balanced expression right after, and after the
text::balanced is done, continue on with my regex search (\G).

this must be a very common problem. is Text::Balanced the right module
for the task? if so, can someone please point me to a simple example?

sincerely, /iaw


Posted by Ch Lamprecht on June 16, 2006, 12:26 am
Please log in for more thread options


ivowel@gmail.com wrote:
> dear perl users: I want to write a function that extracts "ordinary"
> subroutines from perl code. (an equivalent task is extracting all
> macros from a latex file.) I am not trying to be too clever. let's
> presume I can recognize subs because subs and only subs always start at
> the first character of a line and are not anonymous. a sub is followed
> by a name and can contain nested expressions.
>
> I can do plain pattern matching to find the first occurance of the
> first sub: '^sub [a-zA-Z]+'. but now I am stuck. I need to continue

sub my_1st_sub_not_recognized {};
\w = a word character

Christoph




--

perl -e "print scalar reverse q/ed.enilno@ergn.l.hc/"

Posted by ivowel on June 16, 2006, 11:41 am
Please log in for more thread options



Sorry, the pattern for a valid subname was just there for illustration.
I am stuck on how to extract multiple consecutive subroutines that
have nested parens:
# others
sub a { if (0==0) { print "hi"; } }
# more others
sub b{ if (1==0) { print "hi"; } }

regards,

/iaw


Similar ThreadsPosted
Idea: 'throws' attribute for subs May 8, 2007, 4:30 am
Extract Session Cookie February 23, 2007, 3:29 am
text-chm May 6, 2005, 10:53 pm
Help reading PDF to get text... November 26, 2004, 3:50 am
ANNOUNCE: Text::Iconv 1.4 July 18, 2004, 1:41 am
Text::CHM on SuSE 9.3 x86_64 September 19, 2005, 8:08 pm
How to text in HTML::Element October 23, 2004, 7:31 pm
text::tagtemplate question. December 6, 2004, 12:19 am
Module to get text from a PDF page? January 6, 2005, 8:52 pm
ANNOUNCE: Text-Bidi-0.01 August 28, 2006, 2:08 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap