Off By One Error

Robrt on 2005-11-04T04:40:19

I updated the Parrot smokeserver today, and suddenly the output display was horribly garbled. I started taking apart the regular expression, converting it into a //x with comments, and suddenly the answer was clear!

Someone added a field to the middle of the data set, and didn't increment all the following field id's. (I.e., $7, $8, $8, $9...).

Lesson #1: Be careful when inserting to the middle of a set. If you can safely insert at the end, do so.

Lesson #2: Don't use the numbered regexp capture syntax for large numbers of capture groups. Use ($foo, $bar, $baz) = /(.)(.)(.)/ instead.

I didn't write the original code - I just had to fix it. (Luckily, I like fixing things.)


Obligatory Doug Adams reference

jbodoni on 2005-11-04T15:10:53

> Use ($foo, $bar, $baz) = /(.)(.)(.)/ instead.

This is also known as the Eccentrica Gallumbits regex.

John

Re:Obligatory Doug Adams reference

Robrt on 2005-11-04T16:43:39

No, it's a three eyed monster with his head cocked to the left.

Re:Obligatory Doug Adams reference

hfb on 2005-11-05T08:29:28

Why not the Anne Boleyn regex? :)

Re:Obligatory Doug Adams reference

jbodoni on 2005-11-05T21:28:49

Because (.) doesn't look like a mole - at least, not to me. :)

John