Well hey, if it's working, what's to fix? But if it were my script, and the purpose is simply to make sure that two particular lines from an input file become a single line in the output file, I'd do something like this in the "Wanted" function: read the input one line at a time and push each one onto an array, if the current line matches the special pattern, attach the next line to it, and when all the input lines have been read in, write the set to a new output file if that line-joining logic actually applied (if it didn't, no need to rewrite the file).
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" +; } }
(untested)

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.


In reply to Re^6: RESOLVED!!! by graff
in thread remove line break from 1 line by djbryson

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.