Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

RE: When is a while not a while?

by jreades (Friar)
on Aug 24, 2000 at 19:06 UTC ( [id://29432]=note: print w/replies, xml ) Need Help??


in reply to When is a while not a while?

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...

Replies are listed 'Best First'.
RE (tilly) 2: When is a while not a while?
by tilly (Archbishop) on Aug 24, 2000 at 19:25 UTC
    Threaded Perl is labelled experimental for a reason!

    If you want to do this with threads, you will want to write a threaded program in another language and have it call Perl separate interpreters from within the threads.

    Along the same lines, you can always use fork() instead of threads. A little heavier, a lot safer. (Outside of *nix systems which have been optimized for forks, a *lot* heavier or else emulated with threading as described above.)

      What are the tradeoffs between fork() and threads?

      As I said, I've only used threads in Java (which AFAIK has no forking) and they are one of the fundamental classes... Anyway, tradeoffs: discuss.

      TIA

RE: RE: When is a while not a while?
by Miker (Scribe) on Aug 24, 2000 at 19:11 UTC
    Thanks, that gives me more options than I had:) The threading sounds interesting, I'm off to CPAN to see what lurks. Thanks again:)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://29432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-19 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found