Solved

Sorting an array

Posted on 2004-10-13
5
185 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This video discusses moving either the default database or any database to a new volume.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now