http://www.perlmonks.org?node_id=347912


in reply to match and remove across multiple lines

I couldn't get Enlil's code to work until I changed:

print unless ( /^Header1$/ .. /^END LIST$/ );

to

print unless ( /Header1/ .. /END LIST/ );

As originally coded every line was printed.

Update: I did get Enlil's code to work on Solaris 5.9. The only machine it did not work on was the one with Mandrake Linux on it. I have no explanation for that.

xenchu


That's about all there is to it, except for everything else. -<b>Programming Perl</b> (p.346)

Replies are listed 'Best First'.
Re^2: match and remove across multiple lines
by Anonymous Monk on Jan 28, 2006 at 03:15 UTC
    Here is a sample code that works for me. I basically hv to direct the output to another file when I run the script and its working fine. But is there any way to manipulate the insert within the source file itself?.

    Also I am worried about the large xml file and how my memory might be effected

    while (<FILE>) { $match++ if $match; if(/$same/){ # When we see <pattern> start storing the data $match = 1; } $match = 0 if (/APPLES=*/); next if ($match == 1); next unless $match; s/\<Row AutoFitHeight=*//; print "$_"; } foreach $o(sort keys %{$application{$key}}){ print $boots{$s}{$o}\n"; } else { print "0\n"; } } print " $cnt{$s}\n"; print " $date\n"; } close (FILE)

    Edit: g0n - code tags