From 593f7062a2ffb6984b6cd6c020fc4fadacaa51e1 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Mon, 15 Jul 2024 15:48:24 +0800 Subject: [PATCH] add perl os --- study_perl/simple-os/main.pl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 study_perl/simple-os/main.pl diff --git a/study_perl/simple-os/main.pl b/study_perl/simple-os/main.pl new file mode 100644 index 0000000..f460c56 --- /dev/null +++ b/study_perl/simple-os/main.pl @@ -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 = ); + + 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 - 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();