From:                   Booher Timothy B 1stLt AFRL/MNAC <[EMAIL PROTECTED]>

> Hello, I am trying to change all files in a directory that contain the
> strings Satellite satellite and SATELLITE that I need to change to
> target, Target and TARGET. Because many of these are C++ source files
> I need to preserve the case. I was thinking of the following script:
> 
> #!/usr/bin/perl -w
> #UNTESTED
> 
> @FilesInDirectory = <*.cpp *.hpp *.asc>;
> foreach $FileName (@FilesInDirectory) {
>             open(IN, $FileName);
>             while<IN> {
> $_ =~ s/satellite/target/;
> $_ =~ s/Satellite/Target/;
> $_ =~ s/SATELLITE/TARGET/;}
> }


%replace = (
        satellite => 'target',
        Satellite => 'Target',
        SATELLITE => 'TARGET',
);
$re = join('|',keys %replace);
while (<IN>) {
        s/($re)/$replace{$1}/go;
}

Not sure if it'll be any quicker. If you keep your code do not forget 
to add the /g option, otherwise you'd only replace the first 
occurence on each line.

Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
                                        --- me

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

Reply via email to