in reply to Re: How do I display only matches
in thread (SOLVED) How do I display only matches

Shouldn't that be
    next unless $row =~ /REGEX/;
or maybe
    next if $row !~ /REGEX/;


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: How do I display only matches
by tem2 (Novice) on Sep 24, 2019 at 03:28 UTC
    use strict; use warnings; my $filename = 'dirtest.txt'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>) { chomp $row; next if $row =~ /.{20}\\[a-zA-Z]\s[\r\n]/; print "$row\n"; }

    The following is the file content:

    Directory of D:\ \Q\X 09/20/2019 07:57 PM <DIR> . 09/20/2019 07:57 PM <DIR> ..

    The regex works for this content in online regex https://regex101.com/r/LFrvLp/11 But when I run the script, EVERY row is displayed, it should only be the FIRST row as it is the only row with a backslash in position 21.

      Please see this.


      Give a man a fish:  <%-{-{-{-<