CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Sorting values in a CVS

 



narsaw
Novice

Apr 22, 2008, 5:31 PM

Post #1 of 5 (485 views)
Sorting values in a CVS Can't Post

I have a CSV file that looks like:

A | B | C | D | E |
----------|--------|----------|-----------|---------|
16894, 1.096, 0.8224, 68.3945, 1.6172
----------|--------|----------|-----------|---------|
16883, 1.105, 0.8219, 96.0234, 1.9228

The columns (A-E) aren't in the file. The file just looks like:
16894, 1.096, 0.8224, 68.3945, 1.6172
16883, 1.105, 0.8219, 96.0234, 1.9228

The file has about 100,000 entires like these all on separate lines.

Let's say:
Column A is worth five point
Column B is worth three points
Column C is worth one points
Column D is worth four points
Column E is worth two points

I want to know which line (of the two) is worth more total points. This has to be done in perl


KevinR
Veteran


Apr 22, 2008, 6:44 PM

Post #2 of 5 (482 views)
Re: [narsaw] Sorting values in a CVS [In reply to] Can't Post

Hi narsaw,

What have you tried so far?
-------------------------------------------------


narsaw
Novice

Apr 22, 2008, 10:30 PM

Post #3 of 5 (477 views)
Re: [KevinR] Sorting values in a CVS [In reply to] Can't Post


In Reply To
Hi narsaw,

What have you tried so far?


I was just thinking about this today. I haven't started coding yet.

I am looking for some ideas on how to do this efficiently. Not looking for code necessarily (although it would be nice) just some ideas.


KevinR
Veteran


Apr 23, 2008, 1:58 AM

Post #4 of 5 (475 views)
Re: [narsaw] Sorting values in a CVS [In reply to] Can't Post

look into split() and sort()
-------------------------------------------------


agility
New User

May 9, 2008, 8:30 AM

Post #5 of 5 (423 views)
Re: [narsaw] Sorting values in a CVS [In reply to] Can't Post

Hi,

I'd use use Tie::File for manipulating the file.

I'd separate the calculation and sorting steps.

Appropriate use of hashes and arrays should give reasonable efficiency but 100,000 lines isn't too big anyway (if it's a one off job).

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives