hmmmmm. this is certainly a stubborn little script we're dealing with. alright.
About Warnings
use warnings; is equivalent to putting the little -w at the end of your 'shebang line'. So if your Perl implementation does not grok use warnings' change your script to read #!/usr/bin/perl -w at the top of your code. This will have the same effect. Warnings have the effect of telling Perl you want it to complain about any code that's incorrect or not clear. An example would be (at least until Perl 6 comes out):
Without warnings, Perl will compile and run the following code
# this is a slice, probably not intended
@someList[0] = 'foo';
but with warnings, if you tried to use the above code, Perl will complain:
@someList[0] better written as $someList[0]
which is what you want. Using warnings (either through 'use warnings' or the '-w' flag is one of the most important steps you can take towards being a good Perl programmer.
Back To the Problem At Hand
That all being said, 'use warnings;' is not needed to make this script run correctly.
Some Questions
- What version of Perl are you using, and on which platform?
- How big are the directories that you're trying to parse?
- Are the directories local or are they network shares?
And have you tried adding some debugging to the script to see what it's doing? Maybe you want to do something like:
#!/usr/bin/perl -w #alternative warning syntax
use strict;
use File::Find;
#########################################################
# a debugging variable
#########################################################
my $totalChanges;
my @dirs = qw(.);
find ( { wanted => \&change, no_chdir => 1}, @dirs );
sub change
{
my $file = $File::Find::name;
if ( -f $file && $file =~ /\.html$/ )
{
###################################
# debugging print statement
###################################
print "going into $file\n";
my $buffer;
open(IN, $file) or warn "CAN'T OPEN $file!\n";
{
local $/ = undef;
$buffer = (<IN>);
}
close IN;
my $changecount = ($buffer =~ s/FOO/BAR/gi);
if ($changecount)
{
#######################################
# increment debug variable
#######################################
$totalChanges++;
#######################################
# debugging statement
#######################################
print "changed $changecount instances in $file\n";
open(OPF,">$file") or warn "NOT OPENING $file FOR MOD, $!\
+n";
print OPF "$buffer";
close OPF;
}
}
}
###################################################
# debugging statement
###################################################
print "$totalChanges files changed\n";
-
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 How to display code and escape characters
are good places to start.