You probably want to look into the DBI and DBD::CSV modules, which provide an interface.
translation of pseudocode:
use Fcntl qw(LOCK_EX LOCK_UN);
my $header = 'foo';
my $footer = 'bar';
my $prefix = 'baz';
open CSV,$csvfile;
open OUTPUT,">$header";
flock OUTPUT,LOCK_EX;
$, = ","; # output field seperator, joins lists passed to print
while (<CSV>){
print OUTPUT $prefix,$_; # no need to split;
# just so you know : @list = split(/,/,$_);
# will do the trick better than $var1,$var2...
# but you want to chomp($_) first, and set $\ to "\n" perh
+aps
# then you print OUTPUT $prefix,@list
# and CSV is done for you.
}
print OUTPUT $footer;
flock OUPTUT,LOCK_UN; # not really needed, i think
close OUTPUT;
close CSV;
-nuffin zz zZ Z Z #!perl |