Character Classes includes a list of characters included in a square brackets. Matching of any of these characters
result in a match of the character class. The characters inside the bracket with the combination of characters outside
the brackets are matched for in the string.
Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
@word=qw(joel joe john pol doe);
foreach (@word){
if (/[jpd]oe/)
{
print "Matched ! $_\n";
}
else
{
print "Sorry. $_\n";
}
}
Result:
Matched ! joel Matched ! joe Sorry.john Sorry. pol Matched ! doe
In the above example a list is seperated by space as it is prefixed by the "quote words" its split by words,
then in a loop each word is checked to have a pattern "joe" "poe" "doe", because the j,p,d are character classes
any of which along with "oe" is matched for in the string.
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.