Solved

Sorting an array

Posted on 2004-10-13
5
204 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
  • 3
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 100 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check file date before getting folder path 1 72
Replace  text in a file 2 109
.properties file to call function/method 9 61
perl: Cleaning meta tags using RegEX 12 79
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 …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

778 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