If I turn your code into something to exercise your sort the first thing I find is that fc() is missing. Removing that the sort performs as expected:

#!/usr/bin/perl use strict; use warnings; chomp (my @data_lines = <DATA>); # Sort the data lines according to the "Company Name" field and then t +he "Invoice ID" field. @data_lines = sort { my ($company_name_a, $invoice_ID_a) = (split /~/, $a)[0, 1]; my ($company_name_b, $invoice_ID_b) = (split /~/, $b)[0, 1]; ($company_name_a) cmp ($company_name_b) or $invoice_ID_a <=> $invoice_ID_b } @data_lines; print "$_\n" for @data_lines; __DATA__ SEALEVEL SYSTEMS~1 SEALEVEL SYSTEMS, INC.~2 SEBASTIAN COMMUNICATIONS~3 MASQUE SOUND~4 MASSTECH, INC~5 MASTERBILT~6 SE INTERNATIONAL~7

Prints:

MASQUE SOUND~4 MASSTECH, INC~5 MASTERBILT~6 SE INTERNATIONAL~7 SEALEVEL SYSTEMS~1 SEALEVEL SYSTEMS, INC.~2 SEBASTIAN COMMUNICATIONS~3

You will notice that I replaced tabs with ~ to make the column separators easier to see.

So maybe you'd like to update my sample code to show your actual problem?

Update: ah, I see fc is "new" as of about Perl 5.16 and I hadn't "turned it on" even though using Perl 5.20 :(. Restoring fc to the sort doesn't alter the result.

Premature optimization is the root of all job security

In reply to Re: Sorting an array of strings when some of the strings have commas in them? by GrandFather
in thread Sorting an array of strings when some of the strings have commas in them? by perldigious

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.