Made minor changes:
#!perl -w
my $date = localtime(time);
while ( 1 ) {
print "\n COMMAND MENU\n";
print "\n a. Current date and time\n";
print "\n b. Users currently logged in\n";
print "\n c. Name of the working directory\n";
print "\n d. Contents of the working directory\n";
print "\n e. exit";
print "\n Enter a-e:\n";
chomp ($line = <STDIN>);
last if ( $line =~ /^e$/i );
if ($line eq 'a') {
printf "%-s\n", $date;
}
elsif ($line eq 'b') {
print "\n B is close\n";
}
elsif ($line eq 'c') {
print "\n C is not the answer\n";
}
elsif ($line eq 'd') {
print "\n D isn't it either\n";
}
else {
print "\n Try again\n"
}
}
Using the my $date w/in the if just makes another varaible which
disappears after going out of the block. I entered an e to get out of the
loop. Use the perl localtime(time) to get the current date and time.
Wags ;)
-----Original Message-----
From: Jay Grant [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 26, 2002 10:57
To: [EMAIL PROTECTED]
Subject: Perl Menu Script
Hi,
Please forgive this VERY basic perl question .. but I am trying to write a
perl menu script but I can't seem to get the commands to run. I can get a
normal print to work, but not the unix commands (date, who, etc.) Here is
the program ... what am I doing wrong?
#!/usr/local/bin/perl
$date = "/usr/bin/date";
print "\n COMMAND MENU\n";
print "\n a. Current date and time\n";
print "\n b. Users currently logged in\n";
print "\n c. Name of the working directory\n";
print "\n d. Contents of the working directory\n";
print "\n Enter a, b, c, or d:\n";
chomp ($line = <STDIN>);
if ($line eq 'a') {
my $date;
}
elsif ($line eq 'b') {
print "\n B is close\n";
}
elsif ($line eq 'c') {
print "\n C is not the answer\n";
}
elsif ($line eq 'd') {
print "\n D isn't it either\n";
}
else {
print "\n Try again\n"
}
Thanks for any input.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]