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

put this between chomp and print

 next if $row =~ /REGEX/;

Update

Of course this must be inverted

next unless $row =~ /REGEX/;

Thanks anomalous monk

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^2: How do I display only matches
by AnomalousMonk (Archbishop) on Sep 24, 2019 at 01:53 UTC

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


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

      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:  <%-{-{-{-<