Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl # Recursively searchs down thru directories replacing patterns in file +s. # usage zsr 'search' 'replace' 'ext'(optional with no .) # use '' for null string in $replace # ex: zsr 'type1' 'series A' use warnings; use strict; use File::Find; my ($search,$replace,$ext) = @ARGV; if (defined $ext) {$ext = ".$ext"} else {$ext = '.*'}; die "Usage : zsr 'search' 'replace' 'extension' (extension optional)\n +" if ($search eq ""); find (\&wanted, "."); sub wanted { my $open = $_; my $tempfile = 0; if (!($open =~ /$ext$/i) or (-d||-B||-l)) {return} print $open,"\n"; my $mode = (stat $open)[2]; #print $mode,"\n"; #printf "Permissions are %04o\n", $mode & 07777; open (TEMP,">> $tempfile"); open (FH, "< $open") or die "Can't open $open: $!\n"; while (<FH>) { $_ =~ s/$search/$replace/g; print TEMP $_; } close FH; close TEMP; rename ($tempfile, $open) or die "Can't rename $open: $!\n"; chmod ($mode,$open) or die "Can't restore permissions to $open, possib +ly wrong owner: $!\n"; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Making sense of File::Find by zentara
in thread Making sense of File::Find by wazoox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-10-25 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?