in reply to Pipe filenames, then get user confirmation

Howdy cniggeler, welcome to the Monastery!

When you pipe data into a script, its STDIN is connected to that pipe, so if you want to read from the console again, you'll have to close and reopen STDIN:

#!/usr/bin/perl use strict; use warnings; use feature qw/say/; chomp(my @filelist = <STDIN>); close STDIN; open STDIN, "<", "/dev/tty" or die "Cannot reopen STDIN"; foreach(@filelist) { print "Do you wish to modify $_? (y/n) "; my $ans = uc <STDIN>; say "$_ modified" if $ans =~ m/^Y/; }

(There may well be CPAN modules for this sort of thing, too; I haven't checked.)

Replies are listed 'Best First'.
Re^2: Pipe filenames, then get user confirmation
by cniggeler (Sexton) on Sep 03, 2014 at 18:51 UTC
    That worked - thanks! I thought one couldn't close/ reopen STDIN; o/w I would have tried...