You can tweak the map to be map { "avg($_) as $_\n" } to make it a little more legible, and then browse for errors. Did you try running the SQL directly in your db? What about a portion (e.g. w/just a few columns) of it?

If you want to exclude columns, simply grep them out of @cols, or to just ditch the first one, do a shift @cols;

Doing all the average calculations in one command may be a little taxing on my system.

No, doing all the average calculations in many commands is what will tax your system. If you do it in separate statements, you're making the database go through all 6000 rows 30 different times. But if you do it in one statement, it only needs one pass.

Execution ERROR: Can't use AVG on a string! called from ./runsql3.sql at 24.

Ah. that changes things -- DBD::CSV is treating the values as strings. Read the Data restrictions section of the docs where it says that DBD::CSV doesn't correctly handle data types, in particular NULLs. If you insert integers, it might happen, that fetch returns a string.

You might want to try DBD::AnyData instead.. Or in the avg() make sure the value is casted to a number so that it's not treated as a string. or finally, you could just select * all the data (6000 rows) and use perl to loop over it once and average everything.