add perl os
This commit is contained in:
parent
54274c77ac
commit
593f7062a2
33
study_perl/simple-os/main.pl
Normal file
33
study_perl/simple-os/main.pl
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub main {
|
||||
print "Simple OS Simulator\n";
|
||||
print "Type 'help' for available commands.\n";
|
||||
|
||||
while (1) {
|
||||
print "> ";
|
||||
chomp(my $input = <STDIN>);
|
||||
|
||||
if ($input eq 'exit') {
|
||||
last;
|
||||
} elsif ($input eq 'help') {
|
||||
print "Available commands:\n";
|
||||
print " help - show this help message\n";
|
||||
print " date - show the current date and time\n";
|
||||
print " echo <message> - print the given message\n";
|
||||
print " exit - exit the simulator\n";
|
||||
} elsif ($input =~ /^echo (.*)$/) {
|
||||
print "$1\n";
|
||||
} elsif ($input eq 'date') {
|
||||
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
|
||||
$year += 1900; $mon += 1;
|
||||
print "$mon/$mday/$year $hour:$min:$sec\n";
|
||||
} else {
|
||||
print "Unknown command. Type 'help' for available commands.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
Loading…
Reference in New Issue
Block a user