Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Sorting a CSV file

by McDarren (Abbot)
on Jul 17, 2006 at 02:59 UTC ( [id://561639]=note: print w/replies, xml ) Need Help??


in reply to Sorting a CSV file

"4) sort the higest one "

Sort the highest one what?

Do you mean:

  1. sort by bitsin?
  2. sort by bitsout?
  3. extract the highest bitsin value?
  4. extract the highest bitsout value?
  5. something else entirely?

You need to clarify.

By the way, the "sorting by date" that you've implemented does not work. If you enable warnings, you will see the following output:

Argument "12/6/2006 00:07:22" isn't numeric in numeric comparison (<=> +) at foo.pl line 15, <DATA> line 4. Argument "12/6/2006 00:02:23" isn't numeric in numeric comparison (<=> +) at foo.pl line 15, <DATA> line 4. Argument "12/6/2006 00:17:23" isn't numeric in numeric comparison (<=> +) at foo.pl line 15, <DATA> line 4. Argument "12/6/2006 00:12:22" isn't numeric in numeric comparison (<=> +) at foo.pl line 15, <DATA> line 4.
You get that because you are tring to do a numeric sort on "stringified" data. To properly sort by date, you'll need to first convert the strings into something that sort can make sense of. For example, a unix timestamp. Something like Date::Manip or Date::Calc will be useful for that.

Cheers,
Darren

Replies are listed 'Best First'.
Re^2: Sorting a CSV file
by farhan (Novice) on Jul 17, 2006 at 03:44 UTC
    Sorry Darrent I could not make it clear.
    Sort by date, bitsin,bitsout, compare bitsin and bitsout and keep the highest one, sort the highest value which you get from previous comparision
    Out put should look like as date, bitsin, bitsout, highest one, sort highest one
    01/01/2006 00:03:12, 210, 212, 212, 212
      I'm sorry but I honestly don't understand what it is that you want. I've read it through over and over again and I just don't get it. Hopefully somebody else will be able to understand and point you in the right direction.

      Again, I'm sorry.
      Darren

Re^2: Sorting a CSV file
by farhan (Novice) on Jul 17, 2006 at 03:40 UTC
    Darren, Thanks for reply.If u enable warning, it gives error otheriwse it is sorting by date. later on I will use different approach
    but in mean time i want solution. Do you know how can i solve my above mentioned problem?
      "..it gives error otheriwse it is sorting by date"

      No. As I already pointed out, it is not sorting by date at all. It only appears to be be working because your sample data happens to be ordered by date. Try re-arranging the lines in your sample data and you will see what I mean.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://561639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-20 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found