Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Ask for STDIN but don't pause for it

by ww (Bishop)
on Sep 27, 2011 at 21:13 UTC ( #928185=note: print w/ replies, xml ) Need Help??


in reply to Ask for STDIN but don't pause for it

A very strong + + for zentara's third example (in the readmore, above).

Alternately, however, your description makes me wonder (or maybe it's the mosquitos and the heat) if you really mean your process (script) has to "run continuously" -- the "maybe..." clause might be satisfied by something intermittently self-interupting. *

Downside: user has to manually tell a process to resume (run again, in this trivial example); upside, -- I think -- might be slightly reduced overhead:

#!/usr/bin/perl use strict; use warnings; use 5.012; # 927943 # process to run "continuously" from command prompt unless and until +I want to enter something... say "\n\t Enter 'i' or 'I' followed by <CR> or <CR> (only) to interupt +;\n\t any other char to continue"; my $NOP = "NoInterupt"; my $i = 1; sub continuous { my $continuous = 1; LABEL: $continuous += $i; $i++; say $continuous; # sleep 1; if ($continuous >= 25 ) { say "continuous >= 25, several iterations completed"; return; } goto LABEL unless ( $NOP ne "NoInterupt") ; } sub T { say "this is from sub T (which ain't doing much, but could be used + to deal with an operator input..."; say "for example, try 'R' next time"; return; } sub R { say "About to \"R\" ('run some code')... "; my @foo = qw/foo bar undef 123/; for my $foo(@foo) { say "\t $foo"; } return; } # MAIN START: continuous(); chomp ( my $interupt = <> ); if ( $interupt =~ /[A-H]|[J-Q]|S|[U-Z]/i ) { $NOP = "NoInterupt"; goto START; } elsif ( $interupt =~/r/i ) { R(); $NOP = "R"; goto START; } elsif ( $interupt =~/t/i ) { T(); $NOP="T"; goto START; } elsif ( ($interupt =~/i/i) || ($interupt =~ /''/)) { # exact +ly 'i' or 'I' or no entry $NOP = "\tSCRAM the reactor!"; say "$NOP, \$i: $i"; } =head execution and output: C:\>927943.pl Enter 'i' or 'I' followed by <CR> or <CR> (only) to interupt; any other char to continue 2 4 7 11 16 22 29 continuous >= 25, several iterations completed l 9 18 28 continuous >= 25, several iterations completed r About to "R" ('run some code')... foo bar undef 123 12 s 13 26 continuous >= 25, several iterations completed t this is from sub T (which ain't doing much, but could be used to deal +with an operator input... for example, try 'R' next time 15 u 16 32 continuous >= 25, several iterations completed i SCRAM the reactor!, $i: 17 C:\> =cut

As my very tentative first para indicates, this may be utterly irrelevant, but it seemed worth a shot.

Didactic distinctions -- ignore at will:

wordnetweb.princeton.edu/perl/webwn
(continuous) of a function or curve; extending without break or irregularity

en.wiktionary.org/wiki/continuously
(continuous) Without break, cessation, or interruption; without intervening time; Without intervening space; continued; protracted; extended; Not deviating or varying from uniformity; not interrupted; not joined or articulated;

en.wiktionary.org/wiki/continuous
(Continuous) Uninterrupted; unbroken

---------------

Definition for continually:
seemingly without interruption; "complained continually that there wasn't enough money".
wordnetweb.princeton.edu/perl/webwn

definition of continually by the Free Online Dictionary ...
1. Recurring regularly or frequently: the continual need to pay the mortgage.
2. Not interrupted; steady: continual noise; a continual ...

Continual - Definition from the Free Merriam-Webster ...
1. continuing indefinitely in time without interruption <continual fear>.
2. : recurring in steady usually rapid succession ...

The difference is small, but non-trivial (sometimes). :-)


Comment on Re: Ask for STDIN but don't pause for it
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-12-27 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls