Repeating the array

Discussion in 'Perl Misc' started by Arun, Aug 20, 2008.

  1. Arun

    Arun Guest

    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.
    Arun, Aug 20, 2008
    #1
    1. Advertising

  2. On Tue, 19 Aug 2008 22:55:22 -0700, Arun wrote:

    > 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?
    Leon Timmermans, Aug 20, 2008
    #2
    1. Advertising

  3. Arun <> wrote:
    > 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
    Jürgen Exner, Aug 20, 2008
    #3
  4. On Aug 19, 10:55 pm, Arun <> wrote:
    > 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

    --
    Charles DeRykus
    comp.lang.c++, Aug 20, 2008
    #4
  5. Arun

    Ted Zlatanov Guest

    On Tue, 19 Aug 2008 22:55:22 -0700 (PDT) Arun <> wrote:

    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;
    }
    Ted Zlatanov, Aug 20, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lewis

    datalist repeating first record

    Lewis, Aug 22, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,935
    Ignacio Machin
    Aug 22, 2003
  2. Jordan Marton
    Replies:
    2
    Views:
    481
    Yan-Hong Huang[MSFT]
    Aug 1, 2003
  3. Kenneth

    Repeating asp.net grid headers

    Kenneth, Aug 10, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,200
    MS News \(MS ILM\)
    Aug 12, 2003
  4. Craig Buchanan
    Replies:
    2
    Views:
    313
    DJ Dev
    Feb 8, 2004
  5. Jason Lillywhite
    Replies:
    5
    Views:
    264
    Jesús Gabriel y Galán
    Oct 1, 2009
Loading...

Share This Page