On Nov 17, John W. Krahn said:
>You might have a problem with this if there are any characters in $match
>that are special to regular expressions or $match is a sub-set of the
>array element so use either:
>
>my @filtered = grep /^\Q$match$/i, @array;
>
>Or:
>
>my @filtered = grep $_ eq $match, @array;
Ok, here's my regex-vs-eq rant.
1. A regex is for matching a pattern. "X" equals "Y" is not a pattern.
2. A regex can invoke unnecessary overhead.
3. It is easy to write an INVALID regex for "exact" matching (see the
regex above).
4. Use eq.
5. If you want case-insensitivity, use lc() and eq.
Here is the "proper" regex for equating two strings:
if ($this =~ /\A\Q$that\E\z/) { ... }
and for case-insensitivity:
if ($this =~ /\A\Q$that\E\z/i) { ... }
Why would you USE that? It is not comprehensible. I would not use it.
I would use the simple eq operator:
if ($this eq $that) { ... }
and
if (lc($this) eq lc($that)) { ... }
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]