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 !

In reply to Search and replace over line break by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.