The forward slashes are signify a "regular expression".
Regular Expressions. A regex can match a series of characters within a variable and much, much more than that.
Be careful with syntax like "if this variable doesn't match 'not stop'" - that is a double negative and is hard to understand.
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!!