Skip to content

Instantly share code, notes, and snippets.

@kenjiskywalker
Created May 17, 2012 08:49
Show Gist options
  • Save kenjiskywalker/2717493 to your computer and use it in GitHub Desktop.
Save kenjiskywalker/2717493 to your computer and use it in GitHub Desktop.
Perl while yes or no
#!/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