use strict;
use warnings;
my @vars = ('quit','quirly cat', 'cat queue','granit');
print ("any string 'qu' followed by 'it'\n");
foreach (@vars) {
if ($_ =~ /qu(?=it)/) { print ("found <$_>\n"); }
else { print ("no match for <$_>\n"); }
}
print ("\nany string 'qu' not followed by 'it'\n");
foreach (@vars) {
if ($_ =~ /qu(?!it)/) { print ("found <$_>\n"); }
else { print ("no match for <$_>\n"); }
}
####
use strict;
use warnings;
my @vars = ('and gugus for','gugus and', 'gurit for','granit');
print ("any string 'gu' followed by 'gu'\n");
foreach (@vars) {
if ($_ =~ /gu(?=gu)/) { print ("found <$_>\n"); }
else { print ("no match for <$_>\n"); }
}
print ("\nany string 'gu' not followed by 'gu'\n");
foreach (@vars) {
if ($_ =~ /gu(?!gu)/) { print ("found <$_>\n"); }
else { print ("no match for <$_>\n"); }
}
####
use strict;
use warnings;
my @test = ("ananas", "de:mindset:rule1", "en:mindset:rule1", "wiki:welcome", "
de:sidebar", "sidebar", "en:sidebar", "start", "de:start", "en:start");
my ($cnt, $result);
print "start first loop \n";
$cnt=0;
foreach (@test) {
if ($_ !~ /(start|sidebar)/) {
print " >$_<\n";
$cnt++;
}
}
$result = ($cnt eq 4? ">> correct result" : ">> wrong result");
print "end first loop <$cnt> is $result\n\nstart second loop \n";
$cnt=0;
foreach (@test) {
if ($_ =~ /(?!start|sidebar)/) {
print " >$_<\n";
$cnt++;
}
}
$result = ($cnt eq 4? ">> correct result" : ">> wrong result");
print "end second loop <$cnt> is $result\n";
print ">>pgm ended\n";