Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

match exclude

by emjga1 (Novice)
on Mar 17, 2017 at 08:35 UTC ( #1184988=perlquestion: print w/replies, xml ) Need Help??
emjga1 has asked for the wisdom of the Perl Monks concerning the following question:

I have a small bit of code to find RPM's via RHNS

However it currently shows any matching RPM
hostname1 redhat-release
hostname1 redhat-release-notes 52
hostname2 redhat-release

What I need is to find a way to exclude the match on "notes"

for (@{$systems}) { my $systemid = $_->{'id'}; ## package test my $packages = $client->call('system.list_packages', $session, $sys +temid); for my $package (@$packages) { ## the next line limits to the exact rpm you wish or else you get ever +ything next unless $package->{'name'} ~~ /redhat-release/; my $systemname=$_->{'name'} . " "; chomp $systemname; print $systemname . " " ; print $package->{'name'} . " "; print $package->{'release'}; print "\n"; } }

Can any kind Monk help , to exclude "notes"

Replies are listed 'Best First'.
Re: match exclude
by Eily (Prior) on Mar 17, 2017 at 09:16 UTC

    This can be done with a look-ahead assertion which allows you to express something like "that is followed by", or "that is not followed by". /redhat-release(?!-note)/ should do what you want.

      You are indeed a true Monk
      Spot on with your answer , that worked nicly.
Re: match exclude
by hippo (Abbot) on Mar 17, 2017 at 08:57 UTC
    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';
      Perhaps I should have given a bit more in the list

      abe-n-s00008 redhat-release abe-n-s00008 redhat-release-notes 52 abe-n-s00009 redhat-release abe-n-s00009 redhat-release-notes 52 abe-n-s00010 redhat-release abe-n-s00010 redhat-release-notes 52 abe-n-s00070 redhat-release abe-n-s00070 redhat-release-notes 52 abe-n-s00070 redhat-release-server

      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.

Re: match exclude
by huck (Vicar) on Mar 17, 2017 at 08:51 UTC

     next if ($package->{'name'}=~/\-notes$/); will that do it?

      next if ($package->{'name'}=~/\-notes$/);

      Will show ALL the other RPM's which I dont want.

      abe-n-s00010 gnutls-devel 16.el5_10 abe-n-s00010 gok 2.el5 abe-n-s00010 gphoto2 3.el5 abe-n-s00010 gpm 74.1 abe-n-s00010 gpm 74.1 abe-n-s00010 gpm-devel 74.1 abe-n-s00010 gpm-devel 74.1

        added after

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1184988]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2018-05-26 23:46 GMT
Find Nodes?
    Voting Booth?