in reply to Re: writing to stdin
in thread writing to stdin
First, it's not case-insensitive...
Secondly, an answer such as "y should I?" will match :-)
This will do the trick:
print "Are you sure? [y]"; chomp(my $ans = <STDIN>); $ans ||= "y"; if ($ans =~ m!^y(es)?$!i) { # do something } else { # do otherthing }
And another approach:
#!/usr/bin/perl print "Are you sure? [y]"; if (<> =~ /^(y(es)?)?\n$/i) { # answer was yes } else { # answer was no }
|
|---|