http://www.perlmonks.org?node_id=1034976


in reply to Re: Multiline match
in thread Multiline match

patch-5.1.1.21510 is a substring of patch-5.1.1.21510.gpg, hence it should match. All it wants to match is patch-5.1.1.21510, it doesnt care about gpg

Replies are listed 'Best First'.
Re^3: Multiline match
by kennethk (Abbot) on May 23, 2013 at 16:33 UTC

    hdb's point was your code boils down to 'patch-5.1.1.21510' =~ /patch-5.1.1.21510.gpg/;, which is backwards from what you need. The behavior you seek would look more like

    my @array = split('\n',$output); if ( grep { 'patch-5.1.1.21510.gpg' =~ /\Q$_\E/ } @array ) { print "Match found\n"; }
    Though, as implemented, you'd have problems because of whitespace. For this case, you'd probably be better off using index.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      Exactly!

Re^3: Multiline match
by LanX (Saint) on May 23, 2013 at 16:32 UTC
    But your explanation was the other way round.

    plz try to show us a reproducible code example instead of wording.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Sorry about the confusion, the following is the code I have been trying
      my $str = "update patch-5.1.1.21510"; my $patch = "patch-5.1.1.21510.gpg"; if ($str =~/$patch/ms) { print "Yes \n"; }
        thats the way it works

        DB<105> $str = "update\npatch-5.1.1.21510.pgp"; => "update\npatch-5.1.1.21510.pgp" DB<106> $patch = "patch-5.1.1.21510" => "patch-5.1.1.21510" DB<107> $str =~/\Q$patch/ => 1

        $patch must be included in $str not vice versa.

        No need for multiline because your pattern doesn't span multiple lines.

        '\Q' assures that regex syntax like '.' is escaped.

        Cheers Rolf

        ( addicted to the Perl Programming Language)

        Along the lines of your initial code:

        use strict; use warnings; my $PatchPath = "patch-5.1.1.21510.gpg"; my $output = "update patch-5.1.1.21510"; my @array = split /\s+/, $output; if ( grep { $PatchPath =~ /$_/ } @array ) { print "Match found\n"; }

        SORRY: This post is somehow to far up in the chain. Should be a few posts further down...