#!/usr/bin/perl use strict; die "Usage: $0 filename.csv\n" unless ( @ARGV and -f $ARGV[0] ); for my $csvname ( @ARGV ) { my $records = read_csv( $csvname ); if ( ref( $records ) ne 'ARRAY' ) { warn "Unable to pull records from file $csvname\n"; next; } elsif ( @$records == 0 ) { warn "No csv data found in file $csvname\n"; next; } do_something( $records ); } sub read_csv { my $filename = shift; open( IN, "<", $filename ) or do { warn "open failed on $filename: $!\n"; return; }; local $/; my $alldata = ; my @records = grep !/^#|^\s*$/, split( /[\r\n]+/, $alldata ); return \@records; } sub do_something { # because just being able to read is seldom enough... }