Thanks Bill-
Yeah, I just tried that and it works fine now.  Silly me trying to read a
file line by line and try to match mutiple lines.....


-----Original Message-----
From: $Bill Luebkert [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 18, 2002 9:47 AM
To: Nikko Odiseos
Cc: [EMAIL PROTECTED]
Subject: Re: [Perl-unix-users] Multiline substitution


Nikko Odiseos wrote:

> I have just done an xml dump of several thousand records from a db.
> I have to actually go through each one as the xml from the db has the
> following:
>
> <item name="MetaData">
> <value>
> </value>
> </item>
> (all the values in these fields are empty)
>
> but needs to have this instead:
>
> <item name="MetaData">
> <value>
> <item name="prod"/>
> <item name="features"/>
> </value><value>
> <item name="prod"/>
> <item name="features"/>
> </value>
> </item>
>
> I thought this might work but it does not do a substitution:
>       while (<FILE>) {
>       $_ =~ s|(<item name="MetaData"><value>)|$1<item name="prod"/><item
> name="features"/></value><value><item name="prod"/><item
> name="features"/>|smg;
>       print $_;
>       }
>
> Is there an easy way to do this?


If you can slurp the entire file into a vrbl:

You can slurp the file:

{ local $/ = undef;
$_ = <FILE>;
}

And then add a \s* to your RE (to pick up the newline):

s|(<item name="MetaData">\s*<value>)|$1<item name="prod"/><item
name="features"/></value><value><item name="prod"/><item
name="features"/>|smg;
print $_;

__END__


--
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic
http://www.todbe.com/
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to