Computing: DOS, OS/2 & Windows Programming

Installing and running Perl 5 on FreeDOS.


The nice thing with FreeDOS is, that it is an operating system under active development. That means, that not only it's possible to run old DOS applications, but also that there are packages of actual software available for FreeDOS. The best example from my point of view is the Free Pascal compiler for the go32v2 DOS Extender (including a Turbo Pascal similar IDE and a debugger), that makes it possible to use FPC 3.2.2 to create applications for DOS. And there is a Perl package for FreeDOS, too, not some obsolete Perl version from the last century, but Perl 5.8, even not necessary to search for it on the Internet, because it is included on the Bonus-CD of FreeDOS 1.3 RC5.

I did not arrive to install the Bonus-CD packages with the provided install batch file, thus, I did a manual install. To simplify things for myself, I used 7-Zip to extract the package files (located at {CD-Drive}\PACKAGES\DEVEL) on my Windows 10 machine. The folder structure of the extracted files is made of 3 folders called APPINFO, DEVEL\PERL and SOURCE\PERL respectively. DEVEL\PERL contains the subdirectories, that with base package applications, you'll find under \FREEDOS (in particular BIN, containing the binaries) plus some Perl specific folders and an archive called LFNFILES.ZIP, that I extracted to a folder of same name (and deleted the archive). SOURCE\PERL contains an archive called SOURCES.ZIP, that I let as is (I do not intend to use the Perl sources, thus I will copy the archive as is into my FreeDOS installation). Then, I created an ISO with the extracted files, using the freeware application ISO Workshop.

FreeDOS being installed at C:\FREEDOS and the 3 folders mentioned above being in F:\PERL (F: is the drive letter of my CD drive), here, how I did to install the Perl files, using the FreeDOS commands copy and xcopy.

The two screenshots below show a small "Hello World" Perl script, opened in the FreeDOS editor (left) and the execution of the script (right). Note, that my Perl sources are located in D:\DEVEL\PERL and that I set the path to the Perl binaries manually, before running Perl. No "Hello World" displayed, but the error message: Can't locate strict.pm.

Perl on FreeDOS: 'Hello World' script, opened in the FreeDOS editor
Perl on FreeDOS: Libraries not found error message

If it is strict.pm that appears in the message, that's simply because it is the first module stated in the use statement. In fact, the problem is that Perl cannot find the modules directory. Fortunately, there is a very simple way to tell Perl, where to search for modules: all that you have to do, is to set the environment variable PERL5LIB. In our case:
    SET PERL5LIB=C:\DEVEL\PERL\LIB\PERL5

All that Perl needs to know in order to run correctly is the path to its binaries and the path of the library (the directory containing the Perl modules). You can include the corresponding DOS commands in your AUTOEXEC.BAT file or create a Perl batch file. In such a batch file, you can also include a cd to your source file directory, so that you haven't to do this manually. If you like, you can end the batch file by opening the FreeDOS editor, or to run Perl, using %1 to pass the name of the script to be run. The two screenshots below show a new version of my "Hello World" script (left) and its execution (right). A new version, because the system command seems not to work (on FreeDOS or on DOS in general?) and so I had to find another way to clear the screen. There are several Perl packages for screen input-output, but there is also the possibility to use ANSI escape sequences. This will, of course, only work if you have NANSI.SYS (or its MS-DOS equivalent ANSI.SYS) installed.

Perl on FreeDOS: 'Hello World' script with ANSI escape sequences for screen output
Perl on FreeDOS: Execution of a script with ANSI escape sequences for screen output

Using SET's Editor as Perl editor on FreeDOS.

Using the standard FreeDOS editor to write the source code and running Perl from the FreeDOS command line is ok, but wouldn't it be lots nicer to have an editor with syntax highlighting for Perl? And that perhaps even could directly launch Perl and collecting error and warning messages, thus allowing to write and test your script without leaving the editor? Again, no need to search the Internet. FreeDOS 1.3 RC5 includes the programming editor SET's Editor (SETEdit) and it's even installed by default, not in C:\EDIT, as you should expect, but in C:\APPS. SETEdit is without any doubt one of the most configurable editors that exist, it has syntax highlighting for lots of programming languages (that you may re-configure if you want, as well as you can add highlighting for further languages) and it comes with all the features a programmer can dream of. Big thanks to Salvador Eduardo Tropea for this amazing piece of software!

Perl on FreeDOS: 'Hello World' script, opened in the amazing SET's Editor

The power of SETEdit is its capability to use macros, not only those, you create by recording the keystrokes in the Editor window, but also those, you create by writing simple scripts, using sLisp, a Lisp like language. The editor is shipped with some of these macros included (e.g. a "Select all" feature); they are stored in the file C:\APPS\SETEDIT\SHARE\SETEDIT\MACROS.SLP, one behind the other and creating a new macro is just adding the sLisp code to this file. The macro, that I had in mind, should take the Perl source actually being edited, pass it to the Perl interpreter and, if there are errors or warnings, display these in the editor's Messages window. Here the sLisp code:

    ;******************************************************
    ; MACRO: Perl
    ; DESCRIPTION: Run Perl interpreter with file currently being edited
    ; as input. Perl error and warning messages will be displayed in the
    ; Messages window.
    ;******************************************************

    (defmacro 'Perl'
        (eval
            (setv "input" (WhichEditor))
            (if (length input)
                (eval
                    (setv "program" (+ "perl" " " input))
                    (eval
                        (setv "output" (RunProgram program))
                    )
                )
            )
        )
    )

The "heart" of this small script is the RunProgram function, that passes its argument to the DOS command interpreter (i.e. if the argument is a program name, executes this program and if there is something else after the program name, this is passed as arguments to the program to be executed), collects the output at STDERR and sends it to the editor message window. In the SETEdit documentation, it is said that RunProgram collects the output of both STDERR and STDOUT. This is not what happens with my sLisp script: If the Perl script terminates normally, nothing is displayed in the Messages window, i.e. the normal output of the script does not appear here. What isn't a problem, because what I want to have, is the possibility to view the script errors and warnings during the test phase, without having to switch between the editor and the DOS command line. The argument to be passed to RunProgram actually is perl {perl-script-filename}, where {perl-script-filename} is the name of the file, we work on in the (active) editor window. This filename can be retrieved using the function WhichEditor.

The macros, stored in MACROS.SLP are accessible in the editor by choosing Macro > Choose and then selecting the macro, you want to execute. That's what the two screenshots below show. Note, that I modified the Perl script by removing a quote in line 13. This syntax error results in an incorrect highlighting, of course; thus, even without running Perl, you know that there's something wrong.

Perl on FreeDOS: SETEdit programmers editor - Choosing my custom macro to run Perl [1]
Perl on FreeDOS: SETEdit programmers editor - Choosing my custom macro to run Perl [2]

The following screenshots show the execution of the Perl script: At the left, with the error in line 13, and the error message returned by the Perl interpreter displayed in the Messages window; at the right, with the error corrected, normal end of program, nothing displayed.

Perl on FreeDOS: SETEdit programmers editor - Perl script with error displayed in the Messages window
Perl on FreeDOS: SETEdit programmers editor - Perl script without errors terminating normally

I said above that SETEdit is one of the most configurable editors that you can find. Thus, it should be possible to add the Perl interpreter macro as a standard item to the menu bar. The layout of the editor's menu bar is described in the file C:\APPS\SETEDIT\SHARE\SETEDIT\MENUBIND.SMN. Each menu is described by a SubMenu entry, each of its menu items by a MenuItemC entry; MenuSeparator can be used to include a horizontal separation line. For each menu, you have to define the menu item text and the action to be taken; optionally, you can add a keyboard shortcut definition.

The best place to add the Perl interpreter had probably been the Tools&Ops menu. But this one has already so many items, that the height of the list reaches the bottom of the screen. I finally decided to add it at the end of the Macro menu, separated from the rest by a separator line. To run it from the keyboard, I wanted to use the key sequence ALT+M, P (what made necessary to change the key sequence for Macro > Play; I chose to use ALT+M, L for this item). In the MENUBIND.SMN file, the letter corresponding to the menu item launcher key is put between two tilde (~) symbols. Thus my menu item description has to be something like "Run ~P~erl". Concerning the action to be taken, there are per-defined commands. For a macro execution, the command is cm({macro-name}), in our case cm(Perl).

I also wanted to define a keyboard shortcut, allowing to run the Perl interpreter without opening the Macro menu. Most IDEs use F9 or a combination of F9 and a control key for compile and build commands. In the default configuration of SETEdit, F9 is already assigned; free function keys are F4, F7, F8, F11 and (my choice) F12. In the MENUBIND.SMN file, keyboard shortcuts are described by a key constant followed by the text to be displayed in the editor's menu. In my case: kbF12, "F12".

Here the description of the Macro menu in my MENUBIND.SMN file:

    SubMenu: "~M~acro", kbAlM
        MenuItemC: "~R~ecord", cmcRecordMacro, kbShF10, "Shift+F10"
        MenuItemC: "~S~top", cmcStopMacro, kbAlF10, "Alt+F10"
        MenuItemC: "P~l~ay", cmcPlayMacro, kbCtF10, "Ctrl+F10"
        MenuSeparator
        MenuItemC: "~C~hoose...", cmcChooseMacro
        MenuItemC: "R~e~peat", cmcRepeatMacro, kbShF3, "Shift+F3"
        MenuItemC: "~G~enerate Code", cmcGenCodeForMacro
        MenuItemC: "Ru~n~ selected code", cmcRunSel_sLisp
        MenuItemC: "Enter c~o~de to run", cmcRunEnter_sLisp
        MenuSeparator
        MenuItemC: "Pse~u~do macros...", cmcChoosePMacrosList
        MenuSeparator
        MenuItemC: "Run ~P~erl", cm(Perl), kbF12, "F12"
    EndSubMenu

And the screenshot of how the new Macro menu looks in SETEdit:

Perl on FreeDOS: SETEdit programmers editor - Custom menu with Perl interpreter menu item

If you want, you can create a Perl batch file (or modify the existing one), that sets the path to the Perl binaries, sets the PERL5LIB environment variable, navigates to the folder that contains your Perl sources and then launches SETEdit. Being in the directory with the sources, the Open menu opens automatically in the correct directory. Concerning long file names, I'm not sure. Neither how far Perl 5 for FreeDOS supports them, nor if you have to load the LFN driver. I myself do so in my batch file. However, I never tried out, what works and what not.


If you find this text helpful, please, support me and this website by signing my guestbook.