Let me take a moment and see if I fully understand the code, before I move on. I think I am getting excited and ahead of myself. So
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. }
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?
foreach my $row ( sort { $a->[1] <=> $b->[1] } @$sheet ) { print join( ',', @$row ), "\n";
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 JW

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.