[Omaha.pm] Fwd: weird perl bug

Andy Lester andy at petdance.com
Fri Nov 19 08:48:33 PST 2010


On Nov 19, 2010, at 10:40 AM, Jay Hannah wrote:

> Ya, Andy's explanation helped me too. At a glance I had no idea what was going on.  :)
> 
> In array context all the /g matches are slurped out "in one line of code:"

The BIG lesson here is that one should not use flags on regexes if one does not know WHY they are there.  I suspect that the original author had a /g on the regex simply because all of his regexes have them, perhaps because of cut & paste.  This is called cargo culting.

Another classic bit of cargo culting is escaping characters in a regular expression simply because the author fears that it's necessary.  For example, you might be looking for a movie title, "Because of Winn-Dixie", including the quotation marks, in a block of text.  The cargo culter will write that regex like so

    $text =~ m/\"Because of Winn\-Dixie\"/

because he is afraid that " and - have to be escaped in a regular expression.  They do not.

xoa

--
Andy Lester => andy at petdance.com => www.techworklove.com => AIM:petdance







More information about the Omaha-pm mailing list