[Israel.pm] Sophisticated text processing tools

Eitan Schuler Eitan.schuler at exlibris.co.il
Sun Feb 8 05:40:32 PST 2004

I would probably use regex to do this,

use math-time pattern interpolation (??{CODE})
use positive lookahead (?=PATTERN)
use negative lookahead (?!PATTERN)
use positive lookbehind (?<=PATTERN)
and negative lookbehind (?<!PATTERN)

These lookarounds can be also complex.
I would not hesitate to scan the file a couple of times if needed.


-----Original Message-----
From: Jason Elbaum [mailto:Jason.Elbaum at motorola.com]
Sent: Sunday, February 08, 2004 3:15 PM
To: Perl in Israel
Subject: [Israel.pm] Sophisticated text processing tools

I have some complex text processing tasks I'd like to do with Perl, and 
I'm wondering whether there are any well-known techniques or modules 
which would help.

I'd like to make some automated modifications to source code files: read 
a file, make some changes, write it back under a modified name. However, 
the changes are complex, and I'm looking for a tool more flexible than 
regular expressions.

For example, I'd like to be able to 1) find the next place in the file 
which may need to be modified, 2) analyze the area around it to 
determine what to change and how,  3) make the changes, and then 4) 
continue scanning the file from that point.

I might be searching for a variable of a certain name or type, and then 
changing the code which uses it. But the code which uses it might appear 
a line or two before the variable name. So I want to find the point, 
then analyze the area around it.

Can regexps be made to return a string position indicator, or to start 
from a given string position? Should I read the file directly in chunks, 
keeping track of the file position? Are there other options I'm not 
thinking of?


Jason Elbaum

Perl mailing list
Perl at perl.org.il


More information about the Perl mailing list