#!/usr/bin/perl

use strict;
use warnings;

die "Please provide a filename\n" if @ARGV == 0;
open CSV, "<", $ARGV[0] or die $!;

while (<CSV>){
  my @line = split(',',$_);
  $line[0] =~ s/ /-/g; #comment this out with if you prefer to keep spaces as spaces.
  open OUTFILE, '>'.$line[0].'.txt' or die $!;
  print OUTFILE $_;
  close OUTFILE;
}

close CSV;
