Created
May 17, 2012 08:49
-
-
Save kenjiskywalker/2717493 to your computer and use it in GitHub Desktop.
Perl while yes or no
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $file = './test.txt'; | |
if ( -e $file ) { | |
print "allow overrite ok ? [y/n] : "; | |
while ( my $ans = <> ) { | |
chomp($ans); | |
if ( $ans eq "y" ) { | |
open my $ofh, '>', $file; | |
print "ok\n"; | |
print $ofh "ok"; | |
last; | |
} | |
elsif ( $ans eq "n" ) { | |
print "goodbye.\n"; | |
exit; | |
} | |
elsif ( $ans ne "y" && $ans ne "n" ) { | |
print "allow overrite ok ? [y/n] : "; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment