I dont want to have a thread per device constantly running, especially if all its doing is sleeping.

Why not?

This would be how I would do it. Note, I've no way to test the SNMP stuff, so I've just cleaned up the code you posted elsewhere.

#! perl use strict; use threads; use threads::shared; use Net::SNMP; sub polldevice { my( $running, $stop, $host, $community, $delay ) = @_; ++$running; my( $session, $error ) = Net::SNMP->session( Hostname => $host, Community => $community ) or die "session error:" . $session->error; do { my $result = $session->get_request( "1.3.6.1.2.1.1.2.0", "1.3.6.1.2.1.2.1.0", "1.3.6.1.2.1.1.3 +.0" ) or die "request error: " . $session->error; print "Testing ".$host."\n"; print "Number of interfaces: ".$result->{"1.3.6.1.2.1.2.1.0"}. +"\n"; print "uptime: " . $result->{"1.3.6.1.2.1.1.3.0"}."\n"; print "sysOID: " . $result->{"1.3.6.1.2.1.1.2.0"}."\n"; } while not $stop and sleep $delay; $session->close; --$running; } my $stop :shared = 0; my $running :shared = 0; while( <DATA> ) { async{ \&polldevice, $stop, split ' ' }->detach; } $SIG{INT} = sub{ $stop = 1 }; sleep 1 until $stop; sleep 1 while $running; __DATA__ 192.168.1.50 public 10 192.168.1.1 public 25 192.168.1.2 public 60 192.168.1.3 public 45 192.168.1.4 public 12 192.168.1.5 public 59 192.168.1.6 public 01

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Running subroutines at specific times by BrowserUk
in thread Running subroutines at specific times by stellagoddc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.