How to Read From Dosbox in Perl

Reading user input from DOSBox in Perl is coded similarly on every system. Perl doesn't operate differently on different systems, so it's really just a matter of coding it properly. Once the user gives your script data, you can use it however you like. The process of asking for input is straightforward; the potential for difficulty comes later when you need to filter the content input by a user, as an improper data entry can potentially break your script.

DOSBox is a free DOS emulator available for download from dosbox.com. It runs on a variety of operating systems.

Instructions

    • 1

      Open an instance of DOSBox. Now open the perl file you wish to read input from DOSBox.

    • 2

      Create an expression that will ask the user for his input:

      print "Please give us your input.\n";
      $input = <>;
      print "You entered $input !\n";

      If you're looking for a specific kind of input, make sure you don't accept input that doesn't qualify, otherwise it could break your script. You can use the "die" function to do this. If you were only looking for numbers, you could change the above example to:

      print "Please give us your numeric input.\n";
      $input = <>;
      if ($input ~= m/(\D)+/)
      {
      die "You entered something other than a number! Script terminating!\n";
      }
      else
      {
      print "You entered $input !\n";
      }

      The above example uses a regular expression to examine the input from the user. If it finds anything but a number, it will terminate the script. The user will have to run it again and enter the proper input.

    • 3

      Save your file and exit the editor. Now run your script in DOSBox by typing its name and then pressing "Enter." The script will prompt you for input.

Related Searches:

Resources

Comments

Related Ads

Featured