in reply to Forward slashes around argument
Update: italics added to main point. Extraneous \ removed before single quotes.
use strict; use warnings; my @CPC_STP_type =('bus does not stop here','bus stop', 'anything', 'n +ot this stop'); foreach my $type (@CPC_STP_type) { if ($type =~ m/not stop/) #the "m" is optional { print "type=$type......'not stop' detected\n"; } else { print "type=$type......'not stop' was NOT detected\n"; } } print "\n"; =prints type=bus does not stop here......'not stop' detected type=bus stop......'not stop' was NOT detected type=anything......'not stop' was NOT detected type=not this stop......'not stop' was NOT detected =cut foreach my $type (@CPC_STP_type) { if ($type !~ m/not stop/) #the "m" is optional { print "type=$type......We stop here\n"; } else { print "type=$type......We keep going\n"; } } __END__ #watch out for the unexpected! type=bus does not stop here......We keep going type=bus stop......We stop here type=anything......We stop here type=not this stop......We stop here <= Whoa!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Forward slashes around argument
by hippo (Archbishop) on Jul 02, 2019 at 08:03 UTC | |
by Marshall (Canon) on Jul 04, 2019 at 04:13 UTC |