Storing the matching patterns for future use is known as Backtracking.
Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$string = '17-12-76 12:30:15';
if ($string =~m/([0-9]+-[0-9]+-[0-9]+) ([[0-9]+:[0-9]+:[0-9]+)/)
{
print "The Date of Birth is '$1'.\n";
print "<br>";
print "The Date is '$2'.\n";
}
Result:
The Date of Birth is '17-12-76'.
The Date is '12:30:15'.
In the above example, we have two matching patterns one for the date, then for a time,
and the values returned when there is a match can be referred anywhere using "$1" for the first pattern,
"$2" for the second pattern.
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.