The above code is using “strict” since I am using “my” in front of “$sheet” and “$count”. “$sheet” and “$count” are scalars/variable and ‘count’ is getting assigned a negative value. However, I believe “$sheet” is getting set to an empty or undefined scalar that can be defined later. Line 4. Is the start of the while loop; however, not sure what to call ‘<DATA>’ Line 5. Is chomping the ‘\n’ from end of line Line 6. Is adding one to $count to skip the column headers/column titles Line 7. Comment Line 8. Not sure but I think this is saying to skip the top row if there is something in count?? Line 9. Read in row from file??? Line 10. Assign row data into array?? And split on comma Line 11. Use the PUSH command to add what is in $row to @$sheet??? Or do I have that backwards?1. my $sheet; 2. my $count = -1; 3. 4. while( <DATA> ) { 5. chomp; 6. $count++; 7. # skip header 8. next unless $count; 9. my $row; 10. @$row = split( /,/, $_ ); 11. push @$sheet, $row; 12. }
This is where I do my sort as you pointed out in your post, and where I need to format my SORT syntax, which I am reading up on, but you have already assisted with it. Not sure I understand what you mean about “Note that populating a $sheet array ref (rather than a plain @sheet array) is making things a little bit more complicated than they need to be.” What is more complicated? Note – the example I am using is just an example I found on the Internet that I am trying to understand. Thank you JWforeach my $row ( sort { $a->[1] <=> $b->[1] } @$sheet ) { print join( ',', @$row ), "\n";
In reply to Re^2: Help with converting Python script to Perl for CSV sort
by jasonwolf
in thread Help with converting Python script to Perl for CSV sort
by jasonwolf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |