in reply to Making CSV Files from Tab Delimited Files

I was recently tasked with making CSV files from a list of tab delimited files.

This is a trivial text processing task for which Perl is ideally suited.

I slurped the file as they are about 10 Megs and I do my substitutions, but they are slow.

Don't do that. There's no good reason to slurp whole files into memory in this situation. It just makes the task more complicated and is undoubtedly causing the slowness you're observing.

The following Perl script should perform the conversion correctly and be plenty fast enough.

#!perl use strict; use warnings; use English qw( -no_strict_vars ); local $INPLACE_EDIT = '.bak'; while (<ARGV>) { s/"/""/g; s/\t/","/g; s/^/"/; s/$/"/; }