On Tue, 14 Dec 2004, Christopher Spears wrote:
> I'm writing a Perl script where I ask the user a
> question similar to:
>
> Would you like to remove this file?
> Type y or n.
>
> How do I get Perl to receive the answer and act on it?
> I've been looking in some of my books and noticed
> two ways of receiving input <STDIN> and <>. What is
> the difference between the two?
<> will read from the files specified as arguments I believe. I do
this:
print "Would you like to remove this file? (Y/N) ";
my $input = <STDIN>;
if ($input =~ /^[yY]$/) {
unlink($filename) && print "File '$filename' has been deleted.\n";
}
This requires the user to hit y or Y and then ENTER. It is possible to
do this without the enter but it takes more work.
--
Kirk Bauer <[EMAIL PROTECTED]>
http://linux.kaybee.org | www.autorpm.org | www.logwatch.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>