For this you will want to use the substitution operator. The general syntax is:
$scalar =~ s/$find/$replace/; E.g. $scalar = "FooBar"; $scalar =~ s/Bar/Bear/; print $scalar; will print 'FooBear'. In addition two of the most frequently used switches (placed after the third slash) are g and i. 'g' will replace all instances (global), and 'i' will do a case-insensitive search. "$scalar =~ s/bar/Bear/i" will replace 'bar', 'BAR', or 'Bar', while without the 'i', it will only replace 'bar'. If you leave out the 'g' switch, it will only replace the first instance of the pattern match. Hope this helps... -----Original Message----- From: Eric Westrom [mailto:[EMAIL PROTECTED]] Sent: Thursday, December 13, 2001 1:39 PM To: [EMAIL PROTECTED] Subject: Find/Replace Question Let me preface with "Sorry to ask a dumb question but..." With that said, I'm quite new to perl and I wanted to see if there was a way to search a text file for a particular string and replace it with a different value. The end result would be an updated text file on disk with the necessary changes. Example: file.txt exists on the drive. Scalar $Server="Win2kDC1" File.txt contains a string %SRV%. I want to search for every occurence and replace with $Server. File.txt would be updated in place if possible. I have done this before with vbscript and RegExp, but I am new to perl and do not know the syntax. Any help would be greatly appreciated. Again, sorry for the newbie question. Eric _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin -------------------------------------------------------------------------------- This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin
