The "." metacharacter matches all characters except any newline characters in a multi-line string. If the "s"
option of "m//s" is used, embedded newline characters will also be matched. This is convenient to match a pattern
in multiple lines.
Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
if ("a\nb\nc" =~ m/a.b/)
{
print "matched the string a\nb\nc!\n";
}
else
{
print "no match in the string a\nb\nc!\n";
}
print "<br>";
if ("a\nb\nc" =~ m/a.*c/s)
{
print "matched the string a\nb\nc!\n";
}
else
{
print "no match in the string a\nb\nc!\n";
}
Result:
no match in the string a b c!
matched the string a b c!
In the above example the string "a\nb\nc" is matched with the pattern m/a.*c/s, since the newline characters are
present in between the pattern it gives a mismatch as m// does'nt match newline characters, but when the "s" option
is used even if the embedded newline characters are present pattern is matched.
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.