Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: match exclude

by hippo (Bishop)
on Mar 17, 2017 at 08:57 UTC ( [id://1184992]=note: print w/replies, xml ) Need Help??


in reply to match exclude

next unless $package->{'name'} ~~ /redhat-release/;

Are you able to explain why you are using smartmatch on this line? The reason is not obvious to me. If, as the comment suggests you would prefer an exact match then use that instead:

next unless $package->{'name'} eq 'redhat-release';

Replies are listed 'Best First'.
Re^2: match exclude
by emjga1 (Novice) on Mar 17, 2017 at 09:06 UTC
    Perhaps I should have given a bit more in the list

    abe-n-s00008 redhat-release 5.11.0.4 abe-n-s00008 redhat-release-notes 52 abe-n-s00009 redhat-release 5.11.0.4 abe-n-s00009 redhat-release-notes 52 abe-n-s00010 redhat-release 5.11.0.4 abe-n-s00010 redhat-release-notes 52 abe-n-s00070 redhat-release 5.11.0.4 abe-n-s00070 redhat-release-notes 52 abe-n-s00070 redhat-release-server 6.8.0.5.el6

    Redhat-release can also be redhat-release-server

    What I want to exclude is redhat-release-notes

      Yes, that was the missing data - thank you. I still don't see the need for smartmatch. Instead, here is an SSCCE using a standard m match with a negative look-ahead:

      use strict; use warnings; use Test::More; my @good = ( 'redhat-release', 'redhat-release-server' ); my @bad = ( 'redhat-release-notes', 'any-old-nonsense' ); my $re = qr/^redhat-release(?!-notes)/; plan tests => @good + @bad; for my $str (@good) { like ($str, $re, "$str matched"); } for my $str (@bad) { unlike ($str, $re, "$str not matched"); }

      See How to ask better questions using Test::More and sample data for thoughts about presenting questions in this form.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found