Today's WTF

Toby Corkindale tjc at
Thu Nov 15 01:32:08 GMT 2007

My current job is providing me with plenty of WTF moments, but I just had to
share this particular one.

There's a script. It does some work, but it doesn't want to start doing a batch
until there's a certain amount of entries in the DB. I don't see any good
reason for it to wait, but that's not important right now.

The script does this:
my $rowsReturned = 0;
my $rowsToCollect = a_big_number;
while ($rowsReturned != $RowsToCollect) {
  # SELECT * FROM abigtable order by aField limit $rowsToCollect
  # goes into $query
  $rowsReturned = $query->rows;
  sleep(1) unless $rowsReturned == $rowsToCollect;

There are two problems here.
1) your DBA is going to hunt you down and put an icepick through your head.
2) if the DB updates fast enough, $rowsReturned may jump more than one row per
iteration, and once $rowsReturned is > $rowsToCollect, the LOOP NEVER ENDS. In
which case it won't just be the DBA after your head.


This code has been live for 2.5 years.


More information about the mailing list