in reply to Perl Multiple If Conditions with Match Variables

Hi razmeth, welcome to the Monastery!

You can't even use the named captures, as %+ is reset on each match, too. Fortunately, you can store the matching parts in variables - just make sure the assignment forces list context:

#!/usr/bin/perl use warnings; use strict; my @output = qw( Xmatch3X Xmatch4X Xmatch0Xmatch2X nomatch nomatch nomatchnomatch ); for my $x (0, 3) { if ($output[$x+2] !~ /.*match1.*/ and my ($m1) = $output[$x+2] =~ /.*(match2).*/ and my ($m2) = $output[$x] =~ /.*(match3).*/ and my ($m3) = $output[$x+1] =~ /.*(match4).*/ ){ print "Matched: $m1 $m2 $m3.\n"; } }

The parentheses after my are needed for the list context.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Perl Multiple If Conditions with Match Variables
by razmeth (Acolyte) on Dec 31, 2015 at 19:00 UTC
    Perfect, thank you very much! I've read on here for years, but this is my first posting. I could not have asked for faster or better assistance, thank you again!