Matching at the Beginning and End
To match at the beginning of a string use the carat ^:
$vg="London";
if ($vg =~ m/^Lon/) {
print "vg Matches ";
}
$bh="Visit London";
if ($bh =~ m/^Lon/) {
print "bh Matches ";
}
Which Prints:
vg Matches
-The carat ^ says to match what follows (Lon) only if at the beginning of the string.
-Your variable $vg starts with Lon so it matches and prints.
-Your variable $bh doesn't start with Lon so it does not print.
-If you removed the carat from the second section, the match would occur because Lon is in the $bh string, just not at the beginning.
Copy and Paste Perl Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$vg="London";
if ($vg =~ m/^Lon/) {
print "vg Matches ";
}
$bh="Visit London";
if ($bh =~ m/^Lon/) {
print "bh Matches ";
}
exit;
Match at the END
Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
| | Dojo Matthew A. Russell... | |
| | | |
| | | |