You may want to start looking at some XML parsing modules, but assuming this
is a quickie, I can point out that your problem is starting with the use of
forward slash.

Remember: your forward slash is your separator for the regular exp.

Try replacing it with something else like | or % and go from there - You can
do it!

Like this:
s| _\</pat|"</pat"|g

Not:
s/ _\</pat/"</pat"/g



-----Original Message-----
From: Saskia van der Elst [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 03, 2003 12:26 PM
To: [EMAIL PROTECTED]
Subject: search and replace using regex


I have trouble executing a search and replace through all files in a certain
directory.

I want to replace " _</pat" by "</pat"

Can I match a white-space?

I have tried the following regex:

s/ _\</pat/"</pat"/g

and tried to incorporate it in the following script:

#!/usr/local/bin/perl -w
use strict;
use warnings;
open(INFILE,"<A_Z.xml") || die "Couldn't open file for
reading!\n";
open(OUTFILE,">A_Z.new") || die "Couldn't open file.new
for writing!\n";
while(<INFILE>){
        $_ =~ s/"_\</pat"/"\</pat"/gi; #g for every occurrence, i for
case-insensitive
        print OUTFILE $_;
}
close INFILE;
close OUTFILE;
rename("A_Z.new","A_Zclean.xml") || die "Couldn't rename the
new file!\n"; #automatically kills the old file

{
local ( $^I, @ARGV ) = ( '.bak', 'B' );
s/\b_\</pat\b/\</pat/g while <>
}

The docs don't answer all my questions. Any help will be highly appreciated.
I wish there was an absolute-beginners list...

Saskia

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to