#!/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();