Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- PERL 4.0 Reference Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

     MS-DOS CONSIDERATIONS

     This section describes the MS-DOS version of  perl.   MS-DOS
     perl  has  been  tested with MS-DOS versions 3.2, 3.3, 4.01,
     and 5.0, and should work with 2.0 or  higher.   640  K-bytes
     are needed to get anything done.  MS-DOS 5.0 running in high
     memory is recommended.

     Command-Line Arguments in MS-DOS

     MS-DOS perl recognizes the MKS calling conventions.  The MKS
     Korn  shell  will expand the command-line wildcards and pass
     perl arguments in a manner similar to Unix.   Large  numbers
     of  arguments can be passed this way, and -e commands can be
     enclosed in single quotes just as in Unix.  This works  even
     if  $MKSARGS  (see  the section on the environment below) is
     not set, but not if MKS support is compiled out.

     When invoked from a non-MKS tool with MKS  tooling  present,
     perl will use the MKS glob program (see $GLOB in the section
     on the MS-DOS environment, below) to expand the wildcards.

     When run on a system that doesn't have MKS tools, perl  will
     attempt  to  expand  wildcards it sees in the argument list.
     It is not possible to handle -e arguments  properly  due  to
     limitations in the standard MS-DOS calling conventions.

     Unix and MKS do globbing  differently  than  MS-DOS.   Under
     Unix  and MKS, "abc*" matches abc.c,  Under DOS, though, the
     * won't match "."  The MKS tools use the former  interpreta-
     tion; the perlglob.exe program distributed with perl and the
     globbing built  in  to  perl.exe  use  the  latter.   (Don't
     install  the  distributed  perlglob.exe if you are using the
     MKS tools.)

     File names in MS-DOS

     Perl scripts should use forward slashes to delimit path name
     components. (C programmers should note that most MS-DOS com-
     pilers support this,  too.)   MS-DOS  perl  will  work  with
     backslashes,  but  they  make code unnecessarily messy since
     they must be escaped any time they might be  interpreted  to
     mean  an  escape  sequence.  Subprograms may or may not like
     forward slashes: most programs compiled from C  source  like
     them  fine, but command.com won't take them.  Slashes can be
     reversed before invoking a subprocess using the perl substu-
     tion features.  Inside perl, the following are equivalent:

     "c:/new/report"
     "c:\\new\\report"

     Drive prefixes are optional.  If omitted, the file is sought
     on the current drive.

     Globbing <> Expressions on MS-DOS

     Expressions like <*.c> are expanded by a subshell  in  Unix.
     On  MS-DOS  there  are two cases.  If $MKSARGS is defined in
     the environment and MKS support is compiled in,  the  $SHELL
     is  used,  running echo piped to tr as with the Bourne shell
     on Unix perl.  Otherwise, the supplied perlglob.exe  program
     is  run.   This  program  simply  takes the supplied command
     line, DOS-globs it, and writes the  result,  null-separated,
     to the perl process via a "pipe."

     The MS-DOS Environment

     MS-DOS perl uses a number of environment variables not  used
     by  Unix perl.  This is because the MS-DOS version is widely
     distributed in executable form.  (Not everyone who wishes to
     use perl on MS-DOS has the tools to build it from the source
     code.)  Directory and file names in the environment  can  be
     delimited  with  forward or back slashes.  Environment vari-
     ables are interpreted when  they  are  needed.   (Exception:
     creation of $TMP from $TMPDIR is done at startup.)  Thus the
     perl script can change them.  For example, if a huge  "pipe"
     file  is  to  be  created, and there's room on the hard disk
     (c:) but not the usual $TMP, which is a RAM disk, one  could
     write:

     ENV{'TMP'} = "c:/tmp";
     open (HANDLE, "program|");

     The state of the environment passed to  perl.exe  determines
     argument parsing, though, since this is done before compila-
     tion and interpretation of the perl script.

     PATH        This is the semicolon-separated path list.   The
                 current   directory   is   search  first  unless
                 $MKSARGS is defined and MKS support is  compiled
                 in,  in  which  case  the  current  directory is
                 searched only in response to an explicit "."  or
                 null path component.

     MKSARGS     Set to 1 enable all MKSisms.  The MKS tools  can
                 assume  that the other pieces of the toolkit are
                 lying around, but perl.exe can't.   (It  may  be
                 the  only  MKS-compatible  program on a system.)
                 If have have the MKS tools, you should set  this
                 variable.   Perl will recognize and generate MKS
                 compatible arguments in any  case,  but  without
                 the  switch  will default SLASHC to "-c" instead
                 of "-ce", will fail to run MKS  glob,  and  will
                 run  perl's  glob  instead  of the Korn shell to
                 expand expressions like <*.c>.  (Note  that  MKS
                 support can be compiled out.)

     ROOTDIR     Full  drive  and  path  where  MKS  toolkit   is
                 installed.   Example,  "c:/mks" or "d:/".  Typi-
                 cally is already set in MKS  environment.   Used
                 only  if  $MKSARGS is set and $GLOB is not.  See
                 $GLOB.  Ignored if MKS support compiled out.

     TMP         First  choice   for   temporary   files,   e.g.,
                 "h:\\tmp".    If  not  set,  uses  $TMPDIR  (see
                 below), if that's not set, the current directory
                 is   used.    Swapping  also  goes  here  unless
                 $EXESWAP  is  defined.   Temporary   files   are
                 pseudo-pipes, the swap file, and the -e file.

     TMPDIR      If $TMPDIR is set and $TMP is not, the following
                 is done internally:

                 ( $ENV{'TMP'} = $ENV{'TMPDIR'} ) =~ s,/,\\,g;

                 (Backslashes are reversed as a gesture to decen-
                 dents   of   the  perl  process.)   Creation  of
                 $ENV{'TMP'} from $TMPDIR  is  done  at  perl.exe
                 startup.  Note that the MKS tools use $TMPDIR as
                 a first choice; as a  gesture  of  compatibility
                 for non-MKS users, here, it is a second choice.

     EXESWAP     First choice for swap out file location.  A  RAM
                 disk  is  a  nice  choice.  $TMP is used if this
                 isn't set.  (See also $TMPDIR).  The  swap  file
                 created  the  first time swapping is invoked and
                 is left open until perl exits or does  an  exec.
                 Set to ".off" (note illegal DOS name) to inhibit
                 swapping--useful for  speedy  running  of  small
                 subprocesses.
                  This feature (inhibition) can be turned on  and
                 off.   The  following  example  runs  "ls" using
                 "e:/tmp" as the directory for the swap file.  It
                 then   runs   "who,"   with  swapping  disabled.
                 Finally, it runs "ps" with swapping  re-enabled.
                 Note  that  $ENV{'EXESWAP'}  is set to 'yes' but
                 anything other than '.off' would have sufficed.

                 $ENV{'EXESWAP'} = 'e:/tmp';
                 system "ls";
                 $ENV{'EXESWAP'} = '.off';
                 system "who";
                 $ENV{'EXESWAP'} = 'yes';
                 system "ps";

     GLOB        First choice  for  MKS  globbing  program:  full
                 path,    name,    and    extension.     Example:
                 "d:/mks/etc/glob.exe".  The perl  globbing  pro-
                 gram  (used  for  <*.c>  expansion) is found, as
                 before, via the $PATH.   Used  only  in  an  MKS
                 environment, and then only when perl is run from
                 a non-MKS program.  Ignored if MKS support  com-
                 piled out.

     SHELL       Full path name and extension of the  shell  used
                 used for subprocesses when wildcard expansion is
                 required, e.g., "c:/mks/bin/sh.exe".   If  unde-
                 fined,  COMSPEC  is used.  Presumably this could
                 be the MKS korn shell, but  it  can  be  another
                 shell  (e.g., 4DOS) and thus $SHELL is inspected
                 even if MKS support is compiled out.

     COMSPEC     Full path name of DOS command interpreter, e.g.,
                 "c:\\command.com"  Used  only  if  $SHELL is not
                 defined.  If not found, "\\command.com" is used.
                 (It is bad practice to allow $COMSPEC to default
                 or to have it have anything other  than  a  full
                 drive  and  path name.  You don't want your pro-
                 grams  looking  for  command.com  on   alternate
                 drives.)

     METACHAR    List of characters that  are  metacharacters  to
                 the  $SHELL  or $COMPSPEC.  Used to determine if
                 command can be run directly  or  if  a  subshell
                 must be invoked.  If undefined, \|<> is used for
                 COMSPEC and *"?<>][`'\ for SHELL.

     SLASHC      The  shell  option  for  invoking   a   command.
                 Defaults:   /c  for $COMSPEC, MS-DOS version 4.x
                 or better [sic]; sc, where s is the switch char-
                 acter,  for  $COMSPEC, DOS < 4.0; -ce for $SHELL
                 if $MKSARGS is set and MKS support  is  compiled
                 in.  (The -e needed to get the MKS Korn shell to
                 return the status properly).  The default is  -c
                 for other $SHELLs.  (This is a guess.)

     PERLLIB     Directory(ies)    containing    perl    library.
                 Defaults  to  /usr/local/lib/perl.   Directories
                 are separated like $PATH:  semicolons in MS-DOS,
                 colons  in  Unix.   For  the -P switch, only the
                 first $PERLLIB directory  (or  the  default,  if
                 there's no $PERLLIB) is tried.

     Typical MKS setup (profile.ksh)

     # If you're using the MKS stuff, you probably don't have
     # to do anything other than set MKSARGS and PERLLIB.

     export MKSARGS=1
     # ROOTDIR set by init process or etc.rc or here.
     export TMPDIR=e:/tmp
     # EXESWAP left to default to $TMPDIR
     # GLOB left to default to $ROOTDIR/etc/glob.exe
     # SHELL set by init process or here.
     # COMSPEC not used by perl.exe but probably defined for other uses.
     # METACHAR not defined, left to default.
     export PERLLIB='c:/lib/perl;d:/usr/me/myperlib'

     Typical non-MKS setup (autoexec.bat)

     Rem You probably don't need to do anything except set $TMP,
     Rem which you may be doing anyway.

     Rem MKSARGS not set
     Rem ROOTDIR not used
     set TMP=d:mp
     Rem EXESWAP left to default to $TMP
     Rem GLOB not used
     Rem SHELL not set
     Rem COMPEC set by config.sys SHELL command or by MS-DOS startup.
     Rem METACHAR not defined, left to default.
     set PERLLIB=c:/lib/perl

     Running Subprocesses on MS-DOS

     Perl will by default swap itself out almost entirely when it
     runs  a  subprocess other than MKS $GLOB.  (See the $EXESWAP
     environment variable).  The swap file  is  opened  when  the
     first subprocess is run and is left open until perl exits or
     does an IR exec .  The command line to be run is scanned for
     $METACHARacters  as described above.  If none are found, the
     subcommand is invoked  directly.   If  metacharacter(s)  are
     found, a $SHELL or $COMSPEC is invoked to run the command.

     Use of a single | in a open() command does not constitute  a
     metacharcter:   this  is a directive to perl to open a pipe.
     The following, too, has no SHELL  metacharacters  since  the
     subprocess is simply pwd:

     chop($direct = `pwd`);

     Beware of MS-DOS "internal" commands; i.e., those  that  are
     built   into   command.com.   Examples  are  DIR  and  COPY.
     COMMAND.COM users can use these directly if the command  has
     $METACHARacters;   if  not,  you  must  invoke  an  explicit
     command.com.  In the first example below, '>' is a metachar-
     acter.   In  the second example, there are no metacharacters
     and so the internal "ver" command must be run with an expli-
     clit $COMSPEC.

          system "dir >my.fil";
          system "$ENV{'COMSPEC'} /c ver";

     Users of $SHELLs other than COMMAND.COM must use the  second
     format for anything to be passed to command.com.

     Be aware that no wild card expansion is going to be done  by
     command.com usless you're using one of the built-in commands
     that does it (e.g., COPY).  You can use <> expansion to  get
     around  this.  Even those who have fancy $SHELLs should take
     note of this, since having perl run the $SHELL and then  the
     command  uses less memory than if perl runs the $SHELL which
     runs the command:

          $files = <*.c>;
          `the_com $files`;

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson