Repeating the array

A

Arun

Hi,
I just wanted small help here, i want to repeat an array for every
30 seconds.
lets us keep i want to send an array for every 30 seconds and also
should be able to quit as per the user.
 
L

Leon Timmermans

Hi,
I just wanted small help here, i want to repeat an array for every
30 seconds.
lets us keep i want to send an array for every 30 seconds and also
should be able to quit as per the user.

Really, your question makes no sense. Could you be a little more specific?
 
J

Jürgen Exner

Arun said:
I just wanted small help here, i want to repeat an array for every
30 seconds.

Obviously English is not your first language. Not a problem, but no
matter how hard I try, I can't figure out what you mean by "repeat an
array". First I thought you might mean "copy", but copying an array at
regular intervals doesn't make any sense to me.
Usually you repeat an action, something you (or the program) is doing,
like sending a message or checking for an event. An array is an object
and you can't repeat it, just like you can't repeat a chair or a tree.
lets us keep i want to send an array for every 30 seconds and also
should be able to quit as per the user.

Wild guess: "every 30 seconds" makes me guess that maybe sleep() is what
you are looking for.
On the other hand tasks that need to happen at a regular interval are
often better managed/kicked off by the scheduler of your OS.

jue
 
C

comp.lang.c++

Hi,
I just wanted small help here, i want to repeat an array for every
30 seconds.
lets us keep i want to send an array for every 30 seconds and also
should be able to quit as per the user.

Are you perhaps displaying some ongoing status that needs to be
interruptible by the viewer...?

If that's the case, maybe:

eval {
local $SIG{INT}=sub {die ...};
while (1) { #display loop
...
sleep 30;
}
};
if ($@) {...}


details:
perldoc -q timeout
 
T

Ted Zlatanov

A> I just wanted small help here, i want to repeat an array for
A> every 30 seconds. lets us keep i want to send an array for every 30
A> seconds and also should be able to quit as per the user.

The only tricky part below is the read_key routine. You need to define
repeat_array() yourself.

Ted

#!/usr/bin/perl

use Every;
use Term::ReadKey;

while (1)
{
# check for user input and quit if it was 'q'
my $key = read_key();
last if (defined $key && $key eq 'q');

# repeat an array, whatever that means
repeat_array() if every(seconds=>30);

# print status
print "Hello again\n";
}

# read_key: read a single key from the keyboard
sub read_key
{
my $key;
ReadMode 3;
$key = ReadKey(1); # 1-second wait for a key; you can also use -1 for immediate return
ReadMode 0; # Reset tty mode before exiting
return $key;
}
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top