in reply to Small Code Snippet from PHP to Perl

With which parts of the PHP do you have problems?

For database access, DBI is the closest to mysql_query you will get. The translation should be fairly straightforward though.

For fopen, fwrite and fclose, see open, print and close.

I think there is a logic error in the original PHP code, because it seems to always skip the first row of the returned results. There is one mysql_fetch_assoc() call outside the while loop, and unless the first call is just to "prime the pump", that call will discard the first row.