|
Posted by Martien Verbruggen on March 22, 2008, 2:59 am
Please log in for more thread options
On Sat, 22 Mar 2008 14:10:47 +0800,
>
> By using the following codes:
>
> if ($aref1->[3] =~ /$tomatch/i) {
> print "A:$tomatch\tB:$aref1->[3]\n";
> <STDIN>;
> last;
> }
>
> I discover that the program gives me a match for the following pair:
>
> A:conserved hypothetical B:CONSERVED HYPOTHETICAL W
>
> Indeed I expect that is a mismatch (but not the other way round for matching
> A with B). How to enforce matching the whole expresson (i.e. including the
> "W" in this case) ?
Anchor it at the front and back with ^ and $, or \A and \z. See the
perlre doucmentation for details.
But if you want to test for equality, it might be faster and more
readable to simply lowercase (or uppercase) both strings, and test with
eq. If you know that one of your astrings is always entirely upper or
lower case, it becomes even cheaper to do.
if (lc $aref1->[3] eq lc $tomatch) { ... }
Martien
--
|
Martien Verbruggen | Freudian slip: when you say one thing but
| mean your mother.
|
|