ThePotPlants <> wrote:
> I have a nasty set of text data that I want to sort into order, and remove
> duplicates from.
Please check the Perl FAQ *before* posting to the Perl newsgroup!
perldoc -q sort
perldoc -q duplicate
> This would only have taken 5 seconds in SQL, but I have no idea how to do it
^^
> in Perl.
Me either because you have left the "it" unspecified AFAICT.
Maybe you want to sort by date?
The Subject says sort by date, but your sample data are all
the same date, so that isn't it.
Maybe you want to sort by time?
Nope, your sample data is already sorted by time.
If you tell us what you want done, it will be much easier for us
to help you get it done...
> Data looks like so...
>
> -33.580333 162.601833 01/12/2003 00:01:09
> -33.579833 162.601667 01/12/2003 00:01:51
> -33.579167 162.601500 01/12/2003 00:03:09
> -33.578667 162.601333 01/12/2003 00:04:51
> -33.578667 162.601333 01/12/2003 00:05:09
>
> What would be the most common approach to acheive this?
That depends on what your "this" is and you haven't shared that.
What columns do you want to sort by?
What columns do you want to uniqify?
> Can you insert each line of data into an array, and perform operations on
> specific parts of it?
Sure. By using an "array slice" see perlsyn.pod.
> Any suggestions would be greatly appreciated.
Since you haven't specified a problem that we can solve, I'll make
one up.
Sort by time column, forget about finding duplicates.
Adapting the Schwartzian Transform code given in the answer
to one of your Frequently Asked Questions:
-----------------------------------
#!/usr/bin/perl
use warnings;
use strict;
my @records = <DATA>;
my @sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, (split)[3] ] } @records;
print for @sorted;
__DATA__
-33.579167 162.601500 01/12/2003 00:03:09
-33.579833 162.601667 01/12/2003 00:01:51
-33.578667 162.601333 01/12/2003 00:04:51
-33.578667 162.601333 01/12/2003 00:05:09
-33.580333 162.601833 01/12/2003 00:01:09
-----------------------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas