Ktb wrote:
> 
> The program below works as intended.  It recursively searches
> directories and changes any instances of "spike.domain" to
> "spike.lib.domain" without making a backup (I will already have the
> directory backed up).  There are two things I would like to have the
> program do that I'm having trouble with.
> 
> 1) I would like to make it skip processing itself.

Are you saying that the program is in the same directory as the data
files?  Why?

> 2) I would like it to print out the name of changed files.
> 
> Two of my best attempts to make the modifications:
> 
> 1) Changing the "if" statement to "if ((-f) && (! $0))"
>    To me that says, "if it is a file and not program name."
>    Trouble is when I run it no substitutions are made in the file.
>    No errors reported either.
> 
> 2) I have added, just outside the loop -
>    print "Changed: $File::Find::name";
>    This reports all files as having been changed instead of just files
>    changed.

You need a flag to signal that changes were made.


> Any help appreciated:)
> 
> #!/usr/bin/perl -i
> use strict;
> use warnings;
> use File::Find;
> 
> my $dir = ".";
> 
> find(\&edit_files, $dir);
> sub edit_files {
>     if (-f) {
>         my $file = $_;
>         local @ARGV = ($file);
>         while(<>) {
>             s/spike\.domain/spike\.lib\.domain/;
>             print;
>         }
>     }
> }


This is probably what you want.

#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Basename;

my $prog = basename( $0 );
my $dir = '.';

find( sub {
    return unless -f;
    return if $_ eq $prog;

    local( $^I, @ARGV, $_ ) = ( '', $_ );
    my $change;
    while ( <> ) {
        $change++ if s/spike\.domain/spike.lib.domain/;
        print;
        }
    print "Changed: $File::Find::name\n" if $change;
    },
$dir );

__END__


John
-- 
use Perl;
program
fulfillment

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

Reply via email to