Jay Grant wrote:
>
> Hi,
Hello,
> 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.
Something like this should work:
#!/usr/local/bin/perl -w
use strict;
use Cwd;
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 q. Quit\n";
print "\n Enter a, b, c, d, or q:\n";
chomp( my $line = <STDIN> );
if ( $line eq 'a' ) {
print scalar localtime, "\n";
}
elsif ( $line eq 'b' ) {
system 'who';
}
elsif ( $line eq 'c' ) {
print cwd, "\n";
}
elsif ( $line eq 'd' ) {
system 'ls', '-l';
}
elsif ( $line eq 'q' ) {
last;
}
else {
print "\n Try again\n";
}
}
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]