Hey everybody. I have a simple problem that has been stumping me. I'm
using Perl 5.6.1 on Mac OS X 10.1.1. This is a sub for opening a file in
my program. this is the sub, and the problem is when i run it, if i do
not enter a number 1-3, it keeps asking me forever to enter a number.
Even if I enter a number 1-3 after the first run, it keeps asking me to
enter a number.
Thanks for all the help you guys have been giving to everyone, I have
learned much.
sub start {
print "What would like to do?";
newline();
print "1. Start a new file";
newline();
print "2. Append to a file";
newline();
print "3. Close a file";
newline();
print "Enter a number: ";
chomp(my $response=<STDIN>);
if ( $response eq '1' ) {
print "Enter the new filename: ";
chomp(my $newfile=<STDIN>);
while (-e $newfile) {
print "I see you already have a file named $newfile\n";
print "Please enter a different filename: ";
chomp($newfile=<STDIN>);
}
open(MYFILE, ">$newfile") || die "cannot create: $!";
print_header();
}
elsif ( $response eq '2' ) {
print "Enter the file you wish to applend to: ";
chomp(my $newfile=<STDIN>);
unless (-w $newfile) {
print "I see you already have a file named $newfile\n";
print "The problem is I can not write to it.\n";
print "Please enter a different filename: ";
chomp($newfile=<STDIN>);
}
open(MYFILE, ">>$newfile") || die "cannot append: $!";
} elsif ( $response eq '3' ) {
print "Enter the file you wish to close: ";
chomp(my $newfile=<STDIN>);
unless (-w $newfile) {
print "I see you already have a file named $newfile\n";
print "The problem is I can not write to it.\n";
print "Please enter a different filename: ";
chomp($newfile=<STDIN>);
}
open(MYFILE, ">>$newfile") || die "cannot append: $!";
print_footer();
} else {
unless ($response eq '1' || '2' || '3') {
print "Enter a number: ";
chomp($response=<STDIN>);
}
}
}
==========================================================================
======
Remember: it's a "Microsoft virus", not an "email virus",
a "Microsoft worm", not a "computer worm".
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]