I tried the same logic to get my job done as found somewhere but used Text::CSV. Thanks for help Merijn!!
my @sorted = sort {$a->[30] <=> $b->[30] || $a->[0] <=> $b->[0] || $a- +>[1] <=> $b->[1]} @$ref;

Moreover, I'm stuck with other things now: i.) The script runs on my local machinewindows, strawberry perl, but fails on linux servers; looks like the files I'm getting are created on windows. Error captured is:: Line could not be parsed: Inappropriate ioctl for device2032EIF - CR char inside unquoted, not part of EOL12645948 which is because of Carriage return, can't see that with 'vi'. How can I handle this, any help?

ii.) And yes file has inner double quotes in fields as given above; so get below error while executing this; can we handle this?: Line could not be parsed: Inappropriate ioctl for device2032EIF - CR char inside unquoted, not part of EOL12645948 at ./max_sort.pl line 69, <$data> line 60. # CSV_XS ERROR: 2023 - EIQ - QUO character not allowed

my ($file, $sfile) = @_; my $csv = Text::CSV->new({binary => 1, decode_utf8 => 1, auto_ +diag => 1, allow_loose_quotes => 1}); open(my $data, '<:encoding(utf8)', $file) or die "Could not op +en '$file' $!\n"; my $i = 0; my $ref; my $lineCt = 1; my @header; while(my $line = <$data>){ chomp $line; if($lineCt == 1){ @header = $csv->fields(); $lineCt++; next; } if($csv->parse($line)){ my @fields = $csv->fields(); $ref->[$i] = \@fields; $i = $i+1; } else{ warn "Line could not be parsed: $!",$csv->erro +r_diag; } }

In reply to Re^2: Need to sort comma delimited, double quoted file by CSharma
in thread Need to sort comma delimited, double quoted file by CSharma

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.