cniggeler has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am new to perlmonks but have found many useful tidbits in the past! I have an issue and would appreciate assistance.
I would like to pipe filenames to a perl script, and then obtain confirmation from the user before acting on each file. The problem is, while I can get the filenames no problem, the script simply blows past the console read! I've tried clearing ARGV, and flushing stdin, but to no avail.
Here's what a sample session would look like from the command prompt:
$ find . -name (*.html) | xargs grep -l foo | ./myscript.pl Do you wish to modify file1.html? (y/n) n Do you wish to modify file2.html? (y/n) y file2.html modified
and in myfile.pl I would have this:
#!/usr/bin/perl @filelist = <>; { local $/; <STDIN> } for (@filelist) { chomp; print "Do you wish to modify $_? (y/n) "; $ans = uc(<STDIN>); print "$_ modified\n" if substr($ans, 0, 1) eq "Y" }
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pipe filenames, then get user confirmation
by AppleFritter (Vicar) on Sep 03, 2014 at 18:25 UTC | |
by cniggeler (Sexton) on Sep 03, 2014 at 18:51 UTC | |
|
Re: Pipe filenames, then get user confirmation
by Anonymous Monk on Sep 03, 2014 at 18:18 UTC | |
by cniggeler (Sexton) on Sep 03, 2014 at 18:47 UTC |