On Sat, Feb 15, 2003 at 12:33:15PM -0800, John W. Krahn wrote:
> 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?
>
I was creating and testing the prog within the same directory for safety
and convenience. Having the prog skip itself became an interesting
problem to work on.
<snip>
Thanks for laying out the following code John. I've learned a few new
tricks for my bag:) There are a couple things I'm confused about.
1) I've read about "return" but am still trying to wrap my mind around it.
I understand the two return statements skip if it comes across a file
or prog name but where is "returning" returning to?
2) The following line confuses me.
local( $^I, @ARGV, $_ ) = ( '', $_ );
I will take a shot at it.
local
# keep variable within subroutine
( $^I, @ARGV, $_ ) = ( '', $_ );
# there seems to be an assignment going on here and "$^I" means to
change in place. Is "$_" assigned to "@ARGV, $_" and the "''"
assigned to "$^I"? Is "''" for empty lines in the files?
Thanks for your help,
kent
> 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 );
--
To know the truth is to distort the Universe.
Alfred N. Whitehead (adaptation)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]