Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^11: partial matching of lines in perl

by hippo (Bishop)
on Jun 15, 2020 at 14:35 UTC ( [id://11118098]=note: print w/replies, xml ) Need Help??


in reply to Re^10: partial matching of lines in perl
in thread partial matching of lines in perl

Perhaps your algorithm is wrong or perhaps your data isn't what you think it is. Here is an SSCCE:

#!/usr/bin/env perl use strict; use warnings; my @a2 = qw/foo bar baz/; my $match = join '|', @a2; my @a1 = qw/bar quux/; print grep {$_ !~ $match} @a1;

This prints one blank line (for "bar") and one line with "quux" in it. Do you understand why?

Amended thanks to AnomalousMonk for pointing out the error.

Replies are listed 'Best First'.
Re^12: partial matching of lines in perl
by AnomalousMonk (Archbishop) on Jun 15, 2020 at 18:46 UTC
    This prints one blank line (for "bar") ...

    I don't understand this. I get the "quux" line, but I get no blank line. Capturing the output of the grep in an array and then dumping it shows only one item.


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118098]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found