http://qs321.pair.com?node_id=509819


in reply to No interactivity (prompt) after reading from pipe

What everyone else has said so far is right - if you are reading from a pipe, then you cannot simply read from standard input again to read from the terminal.

However, this does not mean that all is lost. On many POSIX systems, you can find the name of the controlling terminal with POSIX::ctermid(); and then open and read from that.

#!/usr/bin/perl -w use strict; use Getopt::Std; use POSIX qw//; my $what; $| = 1; my @hosts; my %opts; while (<STDIN>) { chomp; push(@hosts, $_); } getopts(':dw', \%opts); $what .= ' bla' if $opts{'d'}; $what .= ' blabla' if $opts{'w'}; my $cterm = POSIX::ctermid(); if (! $cterm) {die "No controlling terminal to read prompt from!";} if (! open(CTERM, '<', $cterm)) { die "Couldn't open controlling terminal $cterm: $!"; } print "OK? [Y|n]>\n"; my $yesno = <CTERM>; chomp $yesno; exit 1 if $yesno =~ /^[nN]$/; print "Did not stop, sorry!\n";

Yes, I could have used STDIN there the second time, but I didn't so as to keep it clear where you were reading what from.

--
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/