how to sort a array?

R

roland.yan

Dear Perl friend,
I have a string array, for example @SampleArray, with the date and time
stamp included.

X2819460047100D,13/07/2006 23:50:39,OK,MC8775,R0-0-9,0.983,
X2819460016100D,13/07/2006 21:4:2,OK,MC8775,R0-0-9,0.672,
X2819460027100D,13/07/2006 23:52:39,OK,MC8775,R0-0-9,0.736,
X2819460072100D,13/07/2006 23:54:35,OK,MC8775,R0-0-9,0.825,
X2819460072100D,13/07/2006 23:56:37,OK,MC8775,R0-0-9,0.952,
........
........


Two question I have.
1. How to sort the array based on the date and time stamp.
2. then check the occurence based on the first field, like
'X2819460047100D'.
then push the first occurence into @1stOcc and push second occurance
into @2ndOcc.

not sure is it clear?

Appreciate your help.
Roland
 
P

Paul Lalli

I have a string array, for example @SampleArray, with the date and time
stamp included.

X2819460047100D,13/07/2006 23:50:39,OK,MC8775,R0-0-9,0.983,
X2819460016100D,13/07/2006 21:4:2,OK,MC8775,R0-0-9,0.672,
X2819460027100D,13/07/2006 23:52:39,OK,MC8775,R0-0-9,0.736,
X2819460072100D,13/07/2006 23:54:35,OK,MC8775,R0-0-9,0.825,
X2819460072100D,13/07/2006 23:56:37,OK,MC8775,R0-0-9,0.952,
.......
.......


Two question I have.
1. How to sort the array based on the date and time stamp.

What have you tried so far? Have you checked the Perl FAQ?
$ perldoc -q sort
Found in /software/perl-5.8.5-0/pkg/lib/5.8.5/pod/perlfaq4.pod
How do I sort an array by (anything)?

You may also be interested in CPAN modules like Date::Manip or
Regexp::Common::time
2. then check the occurence based on the first field, like
'X2819460047100D'.
then push the first occurence into @1stOcc and push second occurance
into @2ndOcc.

not sure is it clear?

No, it's not. So if you're not sure it's clear, why didn't you make it
clear to begin with? The first occurrence of *what*? You've posted
your sample input. That's good. But why not make it clear by also
posting your desired output? Also, please include your best attempt at
solving your problem, so we can help you correct it.

Paul Lalli
 
D

Dr.Ruud

(e-mail address removed) schreef:


"How to sort an array?" See `perldoc -f sort`.

I have a string array, for example @SampleArray, with the date and
time stamp included.

X2819460047100D,13/07/2006 23:50:39,OK,MC8775,R0-0-9,0.983,
X2819460016100D,13/07/2006 21:4:2,OK,MC8775,R0-0-9,0.672,
X2819460027100D,13/07/2006 23:52:39,OK,MC8775,R0-0-9,0.736,
X2819460072100D,13/07/2006 23:54:35,OK,MC8775,R0-0-9,0.825,
X2819460072100D,13/07/2006 23:56:37,OK,MC8775,R0-0-9,0.952,

You effectively want to isolate the first two of a group. For an
undisclosed reason you have decided that you want to use an array for
that.

You need to sort the data, on column 1+2, but your column 2 contains
strange time value representations, so you better fix those first.
 
J

Jürgen Exner

Dear Perl friend,
I have a string array, for example @SampleArray, with the date and
time stamp included.

X2819460047100D,13/07/2006 23:50:39,OK,MC8775,R0-0-9,0.983,
X2819460016100D,13/07/2006 21:4:2,OK,MC8775,R0-0-9,0.672,
X2819460027100D,13/07/2006 23:52:39,OK,MC8775,R0-0-9,0.736,
X2819460072100D,13/07/2006 23:54:35,OK,MC8775,R0-0-9,0.825,
X2819460072100D,13/07/2006 23:56:37,OK,MC8775,R0-0-9,0.952,
.......
.......


Two question I have.
1. How to sort the array based on the date and time stamp.

You use the Perl sort() function, see perldoc -f sort.
2. then check the occurence based on the first field, like
'X2819460047100D'.
then push the first occurence into @1stOcc and push second occurance
into @2ndOcc. not sure is it clear?

No, it is not, at least not to me.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top