I'm trying to remove a line break the occurs within a meta tag in multiple documents. This code runs, but doesn't actually work. The Regex matches, but it doesn't actually chomp. And now that i think about it, if this did work it would remove all line breaks in the file. Should I be doing this line by line instead of slurp?
#!C:\Perl\bin\perl.exe
use strict;
use File::Find;
use File::Slurp;
use Time::Local;
print "\nRunning find-slurp_search-within.pl... \n\n";
my $root = "C:/";
print "changing to $root\n";
chdir $root;
my $no_switch=0;
my $no_files=0;
my @log = ();
my $dir;
# find (\&Wanted, "department", "managers", "mybranch", "mycity", "myi
+nfo", "resources");
find (\&Wanted, "working"); #directories - comman delimited
sub Wanted {
print "*Processing: $root$File::Find::name \n";
if ($_ =~ /\.htm(l)?$/i) {
my $file_slurp = read_file("$root$File::Find::name");
if ($file_slurp =~ m/(<meta[\s\r\n\t]+name="revision"[\s\r\n\t]+con
+tent=[\s\r\n\t]+)/i) {
chomp($file_slurp); # remove line break
open(FILE, ">$root$File::Find::name") or die "ERROR: Can't ope
+n $root$File::Find::name";
print FILE "$file_slurp";
close (FILE);
print "file overwritten\n";
push @log,"$root$File::Find::name \n\n";
$no_switch++;
}
$no_files++;
} #end if matches filetype
else { print "file type not processed\n\n"; } #add $_ if you want t
+o see URL of file not processed.
} # end sub
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.