Deb wrote: > Hi, > > I am modifying a file and replacing a string that I find, which works just > fine. However, sometimes there is already a string there that I don't > want to replace, but instead append something to it. > > Here's what I've got so far: (obligatory use statements not included here) > > while (<IN>) { > > s/^This_Text.*$/That_Text = 2/; > > } > > But now, I may already have "That_Text = 2" which I don't want to replace, > but instead append ":New_Text = 4". >
try something like: #!/usr/bin/perl -w use strict; my @s = ("This_Text = 3","This_Text = 2"); for(@s){ print "Before: $_\n"; s/This_Text(.+)/$1=~m#^ = 2$# ? "$_:New_Text = 4" : "That_Text = 2"/e; print "After: $_\n"; } __END__ prints: Before: This_Text = 3 After: That_Text = 2 Before: This_Text = 2 After: This_Text = 2:New_Text = 4 david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]