Hi All

   I am writing a script that will replace all instance of a particular 
word another in a file

The only problem is that I want to match only whole words
eg If $str="the there thee that the";

  I want to change to $str="abc there thee that abc";


$srcstr = 'the'
$dest = 'abc'

$str=~s/([^\w\_\-\.])\Q$srcstr\E([^\w\_\-\.])/$1$dest$2/g;
this doesnt seem to work

I will enclose my entire script here
#!/usr/bin/perl
#
# This will  work as sedfiles  diff being it replaces only whole words
# A word will mean only char seq containing \w \_ \- \.
# No Regex is allowed in srcstring
#

die "Usage $0 <srcstring> <deststring> <file1>..<file2>\n" unless (@ARGV 
 > 2 );

$srcstr =  shift(@ARGV);
$deststr = shift(@ARGV);
{
     local $^I = '~';
     while (<>) {

        # This does not work
        s/([^\w\_\-\.])\Q$srcstr\E([^\w\_\-\.])/$1$deststr$2/g;

         # This works but not what I need
        #s/\Q$srcstr\E/$1$deststr$2/g;

         print;
     }
}




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to