Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stupidest Sort Problem Ever

Status
Not open for further replies.

careerquiz

Technical User
Nov 20, 2007
4
US
Hi everybody,

I have a really stupid sort problem that I haven't been able to figure out. Although, not entirely a novice I've just spent 4 hours trying to sort an array.

Okay here it is:

I have a database.txt file with a header row such as

name|address|category
John|122 Mockingbird|Tools

Okay, I'm using a small script to search the file and pull out matching terms and then place them in a template.

If I sort the using a sort such as

@lines = sort { $a cmp $b } @lines;

the script hangs for awhile then crashes. If I use a reverse sort such as

@lines = sort { $b cmp $a } @lines;

the script completes but the results are in decending order. This is driving me nuts. I'm sure it's something stupid. I think it may have something to do with the header row but not sure. Could really use someones help on this one. I've attached the script to this message. Thank you for your time.

 
use the sort pragma and try different algorithms?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top