I'll take a flyer and suggest a couple of possibilities depending on the behaviour you want::

1. do {} while () -- this would allow the code to execute once before 'hanging' on the while. I can't really envision how this would apply to your situation, but hey, you never know.

2. Threads -- I've got admit that I've only used threading in Java, but there are at least three threading modules on CPAN.

What you'd want to do is have one thread waiting for keyboard input -- I'm not sure what the exact syntax would be, but you'd create the thread with a low priority/nice-ness so that other processes keep running (maybe even a sleep()), and spin off your other process as a seperate thread so that it can run without waiting for keyboard input (assuming that this is the behaviour you want).

The tricky part is establishing a safe way for the two threads to talk to each other -- in Java you have Thread-safe objects/methods that you can essentially use as a lock on your data ('don't read this until I've finished writing to memory/disk...').

I suspect that in Perl this will be a little tougher, but I'm sure that someone can either a) offer actual code, or b) point you to a module, to solve your problem.

Sorry I can't offer actual code, but this is outside the scope of my normal Perl coding...


In reply to RE: When is a while not a while? by jreades
in thread When is a while not a while? by Miker

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.