Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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

by ww (Archbishop)
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:\> 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:
(continuous) of a function or curve; extending without break or irregularity
(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;
(Continuous) Uninterrupted; unbroken


Definition for continually:
seemingly without interruption; "complained continually that there wasn't enough money".

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://928185]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2017-08-17 20:28 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (292 votes). Check out past polls.