develooper Front page | perl.beginners | Postings from August 2009

User input, <STDIN> & Ctrl-D

Tim Bowden
August 28, 2009 04:14
User input, <STDIN> & Ctrl-D
Message ID:
I'm trying to get user input at the end of every loop but it's not quite
working properly.  The possibilities should be (i) an arg to be used in
further processing, (ii) 'nothing' (ie, '\n') to default to next value,
or (iii) Ctrl-D to finish processing altogether.

#!/usr/bin/perl -wT
use strict;

my $control;
do {
  #process my data
  $control = 0;
  print "Next input...\n";
  while (<STDIN>){
    $control = 1; # and use $somevar = $_ for processing...
    print "we continue using input\n";
}while ($control);

print "done: STDIN became not true...\n";


Ctrl-D only works for the first loop through.  Any suggestions?

Tim Bowden Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About