#!/usr/bin/perl
#
# Sort a CSV file alphabetically
#

$numArgs = $#ARGV + 1;

die "Input CSV file required" unless $numArgs > 0;

foreach $num (0 .. $#ARGV ) {

    rename $ARGV[$num],"$ARGV[$num].old"; 

    open(INFILE,"<$ARGV[$num].old") or die "$!";
    open(OUTFILE,">$ARGV[$num]") or die "$!";

    print OUTFILE sort <INFILE>;

    close OUTFILE;
    close INFILE;
}
