in reply to Re^5: RESOLVED!!!
in thread remove line break from 1 line
(untested)sub Wanted { if ( !/\S\.html?$/i ) { warn "$root$File::Find::name skipped\n"; } elsif ( !open( IN, "<", $_ )) { warn "open for read failed on $root$File::Find::name : $!\n"; } else { my @lines = (); my $line; my altered = 0; while ( defined( $line = <IN> )) { if ( $line =~ /<meta\s+name="revision"\s+content=\s*$/i ) +{ $line =~ s/\s*$//; $line .= <IN>; $altered++; } push @lines, $line; } close IN; if ( $altered ) { open( OUT, ">", $_ ) or die "open for write failed on $roo +t$File::Find::name : $!\n"; print OUT @lines; ## NB: no need for quotes here close OUT; } warn "$root$File::Find::name finished with $altered changes\n" +; } }
That assumes you can redirect STDERR to a file, which any decent shell can do (e.g. ksh or bash, both available for ms-windows), to keep all the "warn" outputs for logging. Or you can open a log file in the main routine and always print the logging messages to that. If you just push them onto an array like you were doing (to be printed when the find() function finished), none of the log data would get written in the event of a "die" condition.
Note that when you print an array like this: print "@array" the quoting will normally cause a space character to be inserted between the elements of the array, and you might not want that.
|
|---|