Nothing is done with | No change is made to the default value of $/ (the input record separator; see perlvar), so readline (the <$fh> expression) is reading newline-terminated lines. Then chomp removes the $/ sequence (the newline) from each line. The /.{20}\\[a-zA-Z]\s[\r\n]/ regex requires a [\r\n] (carriage-return or newline) character to match, but chomp has removed the newline, and I doubt there is a \r present with which to match in text that seems to come from a Windows directory listing (update: see this for a more thorough discussion of this point).
c:\@Work\Perl\monks>perl -wMstrict -le "print 'match with \r' if qq{ Directory of D:\\ \\Q\\X \r} =~ /.{20}\\ +[a-zA-Z]\s[\r\n]/; print 'match sans \r' if qq{ Directory of D:\\ \\Q\\X } =~ /.{20}\\ +[a-zA-Z]\s[\r\n]/; " match with \r
Update: Beyond that, the
next if $row =~ /REGEX/;
statement will skip printing if there is a match. You seem to want to print the line if there is a match, so something like
next unless $row =~ /REGEX/;
still seems the way to go (once you get the regex right :) (Update: See also Marshall's reply. It seems like really good advice, although I see no need to stringize "$line" when $line is already a string read from a file.)
Give a man a fish: <%-{-{-{-<
In reply to Re^3: How do I display only matches (updated)
by AnomalousMonk
in thread (SOLVED) How do I display only matches
by tem2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |