glemley8 has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that is meant to sort data by a certain column. It sorts the data, but the output is absent of the first line of data in the source file! Can anyone tell me what's wrong here? Thanks!
open (SOURCE, "<src_data.csv") or die "Can't open file"; open (OUTPUT, ">output_data.csv") or die "Can't create load file"; my $sheet; my $count = -1; my $csv = Text::CSV->new ({binary=>1}) or die "Cannot use CSV: ".Text: +:CSV->error_diag (); my @rows = (); while (my $row = $csv->getline(*SOURCE)){ push @rows, $row; } my $header = shift @rows; foreach my $row (sort {$a->[1] cmp $b->[1]} @rows){ print OUTPUT join(',', @$row), "\n"; }

Replies are listed 'Best First'.
Re: Sorting script deletes first line of data
by philiprbrenan (Monk) on Aug 28, 2012 at 17:18 UTC

    You have moved the first row to $header with shift()

      Wow, I feel silly. Sorry- this wasn't a script I wrote, and as you can tell, I'm just learning Perl. Thanks!