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