Now I'm still confused on this work.Maybe I have not described the problem
clearly.
Fox example,there are some items coming in continuous time piece:
00:00:01 itemA 200
00:00:02 itemB 100
00:00:03 itemC 150
00:00:04 itemD 300
00:00:05 itemE 250
...
(the item appear as 'name => vaule' style. And most of the items's name are
different from others)
In every 5 minutes, I'm doing it as following:
{
sleep 5*60;
my %hash = calculate_from_the_items(); #for each item,I'll plus all the
historical records to a hash value,and the hash key is this item's name.
for (keys %hash){
do_something() if $hash{$_} > LIMIT;
}
clear_the_items_to_null(); #clear all the items's records to null
}
But it's a very simple resolving method.I'm not satisfied with this way.
I want to get this result when each one item is coming:
{
my $sock=shift;
while(<$sock>)
{
my $isTrue = do_judgement();#judge if it reach some a limit in last 5
minutes relative the current time
if ($isTrue){
do_something();
}
clear(); #clear this item's historical record out of 5 minutes
relative the current time
}
}
How can I do it?Any suggestion is welcome.Thanks.
-----Original Message-----
>From: Chas Owens <[EMAIL PROTECTED]>
>Sent: Jan 24, 2006 9:47 AM
>To: Jeff Pang <[EMAIL PROTECTED]>
>Cc: [email protected]
>Subject: Re: count in continuous time piece
>
>On 1/24/06, Jeff Pang <[EMAIL PROTECTED]> wrote:
>> hi,lists,
>> I want to do this work: count something in continuous given time piece,such
>> as 10
>> minutes.Fox example,there are the lines coming to the socket server as
>> following:
>>
>> 1_feifish1_01_1000ybyg:11530514:get
>> 1_swm_mail_01_100k8qte:13901448:get
>> 1_dajia###_01_1006x8jh:11652267:put
>> ...
>> each line is split to 3 fieles: uid,size,type
>>
>> The socket server accept these lines continuely.I want the result: some a
>> uid such as
>> '1_swm_mail_01_100k8qte',when his total size are plus to some a number (fox
>> example,20000000) in the past 10 minutes,then I would do something.But I
>> have no
>> idea about how to do the count in continuous time piece.Is there any
>> suggestion
>> here?thanks.
>snip
>
>If you have access to whatever is writing to the socket then the
>safest thing to do is to add a timestamp that the message was sent.
>Otherwise you will need to maintain the timestamp of the arrival of
>the message. See the select function on (perldoc -f select) how to
>only execute when data is available.
--
http://home.earthlink.net/~pangj/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>