"|" specifies alternate patterns where matching of either one of them results in a match, usually it
checks from left to right and the first one that is matching is taken."|" are used together with parentheses() to
indicate the groupings preferred.
Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
if ("tom" =~ m/for|if|while/)
{
print "matched charatcer in tom!\n";
}
else
{
print "no match in tom!\n";
}
print "<br>";
if ("abadc" =~ m/a(a|b|c)a/)
{
print "matched character in abadc!\n";
}
else
{
print "no match in abadc!\n";
}
Result:
no match in tom!
matched character in abadc!
In the above example the string "tom" is checked for match with "for", "if", "while", since it did'nt match, the string
"abadc" is checked for match to have a string "aaa","aba", "aca" , since it contains the character "aba" it returns a match.
A Note
Simple introduction, basic CGI perl programming codes with examples.
Do send your feedback or suggestions on this tutorial.
This is a copyright content.