Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
As a follow up to a previous question - I am (now) writing a perl script to do a search and replace (the one liners became too cumbersom) and the issue that is killing me is where the string I am searching for (in order to replace it) the string is split over two lines ... bit like this</P.
hello there this is a bad <?string?> that we need to take away. Here is another bad <?st ring?> that needs to go too.
I need to replace all the <?string?> with <xxx> (let's say)
I have this simple little script, but of course it does not span the line like I want it to
#!/usr/bin/perl use strict; print "Info: ARGV is: @ARGV\n"; while (<STDIN>) { chomp; if (-e $_) { # a regular file (might be suited to your needs) # do something with $_ as if it were shifted from @ARGV print "handling file: $_\n"; open IN, "<$_" or die "Can't open $_: $!\n"; open OUT, ">outfile" or die "Can't open outfile: $!\n"; while (<IN>) { s/<?string?>/<xxx>/g; print OUT; } close IN;close OUT; } else { warn "no such file: $_ \n"; } }
(yes, I know, I need to escape the special chars - I left them out for readability for now)
Help !
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Search and replace over line break
by almut (Canon) on Mar 12, 2010 at 16:48 UTC | |
|
Re: Search and replace over line break
by Svante (Sexton) on Mar 12, 2010 at 12:34 UTC | |
by Anonymous Monk on Mar 13, 2010 at 18:48 UTC | |
by Svante (Sexton) on Mar 14, 2010 at 01:29 UTC |