http://qs321.pair.com?node_id=1083668

ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I am parsing a pattern '<default>any text</default>' pattern in a file and wherever found, I want to replace that by '<default>enabled</default>'.
Now the problem is the above mentioned pattern may occur in a single line and in multiple line as well. So the input file may look something like

******* inputfile****************
this is line 1
this is line 2
<default>sometext</default>
this is line 3
<default>some more text
some more in next line
</default>
this is last line
*************************************
I am trying with this, which is working when the pattern is in single line but not for multiple line. The code for multiple line tried is commented out.

use strict; use warnings; use Tie::File; my $file = "inputfile"; my @array; tie @array , 'Tie::File', $file ; my $start = '<default>'; my $end = '</default>'; my $val = 'enabled'; my $replace = $start.$val.$end; print "replace $replace \n"; for (my $i = 0 ; $i <= $#array ; $i++) { #below if block is tried for multiple line pattern but not working # if ($array[$i] =~ /^<default>/../<^\/default>/) if($array[$i] =~ /^<default>/) #this is working { $array[$i] =~ s/^<default>.*<\/default>/$replace/g; } } untie @array;

seeking help on how can it be made to match both the patterns ?