We love the regexes in Perl, but they don't always make sense. If you're doing
if ( $str =~ /^foo$/i )then write it as
if ( lc $str eq "foo" )
My pet peeve is the opposite: people who use a string as the first argument to split(). Not only is it intended to be a regex, but some strings have special behaviour (" " for instance).
-Dom
Re:'$' ne "\\z"
petdance on 2005-02-22T17:32:27
Except that that distinction is irrelevant in this case. It's just trying to match a value coming out of a hash. But point taken.
I'm currently doing this first:$filesearch = "Financials [1994]";
foreach... {
...
if ( $file =~ m/$filesearch/ )...
But it seems so messy.$filesearch =~ s/([][])/\\$1/g;
$filesearch =~ s/([()])/\\$1/g;
Re:A regex question then?
petdance on 2005-02-22T22:23:47
Look at the quotemeta() function. Also the \Q metacharacter.
When the string is in $_, I'll often use a regex for a string comparison so I can avoid spelling out the variable. This is particularly often the case when grep is involved.
It still annoys me though.
And abuse of regexen for string comparisons tends to crop up a lot in badly written scripts by people who don't really know Perl well (such as most of the stuff that circulates on “free CGI scripts!” sites.)