Solved

Sorting an array

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

623 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