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!
In reply to Pipe filenames, then get user confirmation by cniggeler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |