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

User input, <STDIN> & Ctrl-D

From:
Tim Bowden
Date:
August 28, 2009 04:14
Subject:
User input, <STDIN> & Ctrl-D
Message ID:
1251458030.4918.107.camel@mordor
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";
    last;
  }
}while ($control);

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


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

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

Thanks,
Tim Bowden




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About