I just only realized that the OP mixes timed and non-timed code. This only works if jitter is not considered a major problem.

If the timing needs to be quite exact, my usual approach is to run two different process and use some form of interprocess communication. One process fetches the data from the remote server (however long that takes), parses it and then sends the relevant information to the other process that does cyclic processing.

There are many ways to do this, depending on the data size and the operating system. TCP or UDP work OK, Unix Domain Sockets are quite a bit faster though. There are also pipes and stuff.

Often it's quite a lot easier to use an existing messaging solution, though. Again, there are many solutions, depending on your requirements. Personally, i of course will shamelessly plug my own, which is Net::Clacks. There are some examples that should you get started. If not, i'm a regular here. And there is even a small (slightly out-of-date) mini-tutorial here on PM: Interprocess messaging with Net::Clacks. The Upgrade Guide inluded in more recent versions of Net::Clacks also contains quite a lot of information not documented otherwise.

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'

In reply to Re^4: making a loop script with a remote URL call faster by cavac
in thread making a loop script with a remote URL call faster by brandonm78

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.