Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sorting an array

Posted on 2004-10-13
5
Medium Priority
?
230 Views
Last Modified: 2010-03-05
I have the following code:

@strSortedList = sort (@strList);
for($k = 0, $k <= $#strSortedList; $k==)
    {
      print "$strSortedList[$k]\n";
     }

The list is sorted, however, The Uppercase are sorted first, then the lower case, like so:
Afirstfile
Athirdfile
absecondfile
Blah
Bmblahtoo
betc

I would like to sort it, ignoring the case... how can I do this?

Thanks gurus!
holein5

0
Comment
Question by:David Aldridge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 400 total points
ID: 12302653
@strSortedList = sort{lc $a cmp lc $b}@strList;
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 12302736
That did it!

Thanks,
holein5
0
 
LVL 84

Expert Comment

by:ozo
ID: 12302823
for($k = 0, $k <= $#strSortedList; $k++)
    {
      print "$strSortedList[$k]\n";
     }
can also be written
 print "$_\n" for @strSortedList;
0
 
LVL 84

Expert Comment

by:ozo
ID: 12302829
for($k = 0; $k <= $#strSortedList; $k++)
    {
      print "$strSortedList[$k]\n";
     }
can also be written
 print "$_\n" for @strSortedList;
0
 
LVL 1

Author Comment

by:David Aldridge
ID: 12305009
Hey, that's pretty cool.. thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question