[ABE.pm] Re: perl regex Q
Faber Fedor
faber at linuxnj.com
Tue Dec 14 16:49:48 CST 2004
On 14/12/04 17:16 -0500, Ricardo SIGNES wrote:
> The (?= ... ) construct is called a look-ahead assertion.
And that is the Perl magic I was looking for.
> > Also, is there a way to do a perl "edit in place" inside of a perl
> > program other than using backticks (`perl -iBAK -p -e 's/,,/,\\N,/g'
> > foo.txt`) or the system() call?
>
> No.
I guess that's why (different regex)
perl -iBAK -p -e 's/ *NA */\\N/g' foo.txt
works from the command line but doing it from inside a perl program
generates the error:
Missing braces on \N{} at -e line 1, within string
Execution of -e aborted due to compilation errors.
It doesn't matter how many slashes I put in front of the N! :-)
> Consult "perldoc perlrun" and look under the section about -i; it
> explains how -i would be implemented in Perl, more or less.
I'll go read it forthwith.
> > (No, reading the file in a line at a time is not an option.)
> Why not? It's what perl does when you use -i.
Seems a helluva lot faster than when I tried it in a while loop a while
back.
> Give us more real-world information about what you need to accomplish,
> and what the limitations are.
I need to replace "NA" with "\N" (no quotes around either). The file is
900K+ lines long and 136 columns wide and will continue growing
lengthwise. Limitation: time. If I can do the "edit-in-place" from
inside my program, the whole process takes a minute or two. Everything
thing else I've tried (except a while loop) takes 40 minutes or longer.
--
Regards,
Faber
Linux New Jersey: Open Source Solutions for New Jersey
http://www.linuxnj.com
More information about the ABE-pm
mailing list