Sorting case insensitively

Discussion in 'Perl Misc' started by John Deuf, Oct 27, 2003.

  1. John Deuf

    John Deuf Guest

    Is there a way to sort case insensitively an array (without creating
    another array with lowercase values for instance) ?
     
    John Deuf, Oct 27, 2003
    #1
    1. Advertising

  2. In article <>, John Deuf wrote:
    > Is there a way to sort case insensitively an array (without creating
    > another array with lowercase values for instance) ?



    sort { uc($a) cmp uc($b) } @arr;



    --
    Andreas Kähäri
     
    Andreas Kahari, Oct 27, 2003
    #2
    1. Advertising

  3. John Deuf

    Uri Guttman Guest

    >>>>> "AK" == Andreas Kahari <> writes:

    AK> sort { uc($a) cmp uc($b) } @arr;

    >>>>> "BE" == Bernard El-Hagin <> writes:

    BE> my @sorted = sort { lc $a cmp lc $b } @unsorted;

    now make up your minds!! which one of those is better? will there be
    another war on uc vs lc?

    :)

    uri

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Oct 27, 2003
    #3
  4. John Deuf

    Ben Morrow Guest

    Uri Guttman <> wrote:
    > >>>>> "AK" == Andreas Kahari <> writes:

    >
    > AK> sort { uc($a) cmp uc($b) } @arr;
    >
    > >>>>> "BE" == Bernard El-Hagin

    > <> writes:
    > BE> my @sorted = sort { lc $a cmp lc $b } @unsorted;
    >
    > now make up your minds!! which one of those is better? will there be
    > another war on uc vs lc?


    I thought there was a Right Answer to this: lc, as Unicode defines
    mappings upper -> lower and title -> lower...?

    Ben

    --
    For the last month, a large number of PSNs in the Arpa[Inter-]net have been
    reporting symptoms of congestion ... These reports have been accompanied by an
    increasing number of user complaints ... As of June,... the Arpanet contained
    47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] *
     
    Ben Morrow, Oct 27, 2003
    #4
  5. [This followup was posted to comp.lang.perl.misc]

    In article <>,
    says...
    > Is there a way to sort case insensitively an array (without creating
    > another array with lowercase values for instance) ?



    @sorted = sort { uc($a) cmp uc($b) } @data;

    # Note that you could also use "lc" instead of "uc" in
    # the sorting specification
     
    Master Web Surfer, Oct 31, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason
    Replies:
    5
    Views:
    283
    Jason
    Apr 10, 2008
  2. tomaszewski.p
    Replies:
    4
    Views:
    810
    Tom Anderson
    Sep 12, 2008
  3. Knute Johnson
    Replies:
    0
    Views:
    422
    Knute Johnson
    Sep 11, 2008
  4. Roedy Green
    Replies:
    0
    Views:
    422
    Roedy Green
    Sep 12, 2008
  5. PerlFAQ Server
    Replies:
    0
    Views:
    308
    PerlFAQ Server
    Feb 8, 2011
Loading...

Share This Page