[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] find.pl and wanted



Hi.

I've just come across a very interesting "feature" with find.pl and the
wanted subroutine.

For those who don't know, if you use find.pl you can easily work through
subdirectories of files performing your nifty perl scripts on all the files
contained within all subdirectories. There is a subroutine called "wanted"
that you put in your code that allows you to do your dirty work on the
files as find.pl traverses the tree.

Which brings me to my point: find.pl REALLY likes $_ (a personal bane of
mine), so I would advice all you perlers out there to save then restore the
value of $_ in all you wanted scripts.

e.g.

#========================================================================
# Function:     wanted
# Purpose:      This is called by &find() to determine whether a file
#               is wanted.      $dir contains the
#               current directory name, and $_ the current filename within
#               that directory.  $name contains "$dir/$_".  You are cd'ed
#               to $dir when the function is called.  The function may
#               set $prune to prune the tree.
#========================================================================
sub wanted
{
        my ($old_) = $_;

        &dofile($name) if -f $name && &checkfiletype($name);
        $_ = $old_;
}

Ads

-----------------------------------------------------------
Adam Weisser                            ShowAds Interactive
adam@sai.com.au                 http://www.sai.com.au/~adam

"I'll never see myself in the mirror with my eyes closed."
 - They Might Be Giants
-----------------------------------------------------------