April 2011 Archives

Here's a stupid bug.

Suppose you want to check if a number is either 70 or 73, and your duct-tape-and-chewing gum production environment is stuck in the stone age without the smart-match operator.

You might be tempted to write foo() if $num =~ /^70|73$/, as I did. Oops. That will match 70 and 73, but also anything that ends in 73, like 173 or 273 or foo73. /^(?:70|73)$/ fixes it.

The moral of the story: life sucks without smartmatch.

About Mike Friedman

user-pic Mike Friedman is a professional computer programmer living and working in the New York City area.