I have some code like the following:
if (not defined $id) {
print "Enter ID number: ";
chomp ($id = <STDIN>);
exit 0 if ($id eq ""); # If empty string, exit.
}
if (not defined $name) {
print "Enter name: ";
chomp ($name = <STDIN>);
exit 0 if ($name eq ""); # If empty string, exit.
}
if (not defined $class) {
print "Enter class: ";
chomp ($class = <STDIN>);
exit 0 if ($class eq ""); # If empty string, exit.
}
I'd like to be able to potentially pass only some of them (e.g., name and class, but not ID), passing blanks for the unpassed ones, so I thought the following would work:
if (not defined $id || $id eq "") {
print "Enter ID number: ";
chomp ($id = <STDIN>);
exit 0 if ($id eq ""); # If empty string, exit.
}
But it doesn't seem to work if I pass, e.g., the following:
perl "myperlroutine.pl" "" "Mickey Mouse" "Entry"
The command window (I'm running this on Windows) briefly appears and then immediately disappears.
Am I missing something obvious?