3 perlvms - VMS-specific documentation for Perl
7 Gathered below are notes describing details of Perl 5's
8 behavior on VMS. They are a supplement to the regular Perl 5
9 documentation, so we have focussed on the ways in which Perl
10 5 functions differently under VMS than it does under Unix,
11 and on the interactions between Perl and the rest of the
12 operating system. We haven't tried to duplicate complete
13 descriptions of Perl features from the main Perl
14 documentation, which can be found in the F<[.pod]>
15 subdirectory of the Perl distribution.
17 We hope these notes will save you from confusion and lost
18 sleep when writing Perl scripts on VMS. If you find we've
19 missed something you think should appear here, please don't
20 hesitate to drop a line to vmsperl@genetics.upenn.edu.
22 =head1 Organization of Perl Images
26 During the installation process, three Perl images are produced.
27 F<Miniperl.Exe> is an executable image which contains all of
28 the basic functionality of Perl, but cannot take advantage of
29 Perl extensions. It is used to generate several files needed
30 to build the complete Perl and various extensions. Once you've
31 finished installing Perl, you can delete this image.
33 Most of the complete Perl resides in the shareable image
34 F<PerlShr.Exe>, which provides a core to which the Perl executable
35 image and all Perl extensions are linked. You should place this
36 image in F<Sys$Share>, or define the logical name F<PerlShr> to
37 translate to the full file specification of this image. It should
38 be world readable. (Remember that if a user has execute only access
39 to F<PerlShr>, VMS will treat it as if it were a privileged shareable
40 image, and will therefore require all downstream shareable images to be
44 Finally, F<Perl.Exe> is an executable image containing the main
45 entry point for Perl, as well as some initialization code. It
46 should be placed in a public directory, and made world executable.
47 In order to run Perl with command line arguments, you should
48 define a foreign command to invoke this image.
50 =head2 Perl Extensions
52 Perl extensions are packages which provide both XS and Perl code
53 to add new functionality to perl. (XS is a meta-language which
54 simplifies writing C code which interacts with Perl, see
55 L<perlapi> for more details.) The Perl code for an
56 extension is treated like any other library module - it's
57 made available in your script through the appropriate
58 C<use> or C<require> statement, and usually defines a Perl
59 package containing the extension.
61 The portion of the extension provided by the XS code may be
62 connected to the rest of Perl in either of two ways. In the
63 B<static> configuration, the object code for the extension is
64 linked directly into F<PerlShr.Exe>, and is initialized whenever
65 Perl is invoked. In the B<dynamic> configuration, the extension's
66 machine code is placed into a separate shareable image, which is
67 mapped by Perl's DynaLoader when the extension is C<use>d or
68 C<require>d in your script. This allows you to maintain the
69 extension as a separate entity, at the cost of keeping track of the
70 additional shareable image. Most extensions can be set up as either
73 The source code for an extension usually resides in its own
74 directory. At least three files are generally provided:
75 I<Extshortname>F<.xs> (where I<Extshortname> is the portion of
76 the extension's name following the last C<::>), containing
77 the XS code, I<Extshortname>F<.pm>, the Perl library module
78 for the extension, and F<Makefile.PL>, a Perl script which uses
79 the C<MakeMaker> library modules supplied with Perl to generate
80 a F<Descrip.MMS> file for the extension.
82 =head2 Installing static extensions
84 Since static extensions are incorporated directly into
85 F<PerlShr.Exe>, you'll have to rebuild Perl to incorporate a
86 new extension. You should edit the main F<Descrip.MMS> or F<Makefile>
87 you use to build Perl, adding the extension's name to the C<ext>
88 macro, and the extension's object file to the C<extobj> macro.
89 You'll also need to build the extension's object file, either
90 by adding dependencies to the main F<Descrip.MMS>, or using a
91 separate F<Descrip.MMS> for the extension. Then, rebuild
92 F<PerlShr.Exe> to incorporate the new code.
94 Finally, you'll need to copy the extension's Perl library
95 module to the F<[.>I<Extname>F<]> subdirectory under one
96 of the directories in C<@INC>, where I<Extname> is the name
97 of the extension, with all C<::> replaced by C<.> (e.g.
98 the library module for extension Foo::Bar would be copied
99 to a F<[.Foo.Bar]> subdirectory).
101 =head2 Installing dynamic extensions
103 In general, the distributed kit for a Perl extension includes
104 a file named Makefile.PL, which is a Perl program which is used
105 to create a F<Descrip.MMS> file which can be used to build and
106 install the files required by the extension. The kit should be
107 unpacked into a directory tree E<not> under the main Perl source
108 directory, and the procedure for building the extension is simply
112 $ perl Makefile.PL ! Create Descrip.MMS
113 $ mmk ! Build necessary files
114 $ mmk test ! Run test code, if supplied
115 $ mmk install ! Install into public Perl tree
119 VMS support for this process in the current release of Perl
120 is sufficient to handle most extensions. However, it does
121 not yet recognize extra libraries required to build shareable
122 images which are part of an extension, so these must be added
123 to the linker options file for the extension by hand. For
124 instance, if the F<PGPLOT> extension to Perl requires the
125 F<PGPLOTSHR.EXE> shareable image in order to properly link
126 the Perl extension, then the line C<PGPLOTSHR/Share> must
127 be added to the linker options file F<PGPLOT.Opt> produced
128 during the build process for the Perl extension.
130 By default, the shareable image for an extension is placed
131 in the F<[.Lib.Auto.I<Arch>.I<Extname>]> directory of the
132 installed Perl directory tree (where I<Arch> is F<VMS_VAX> or
133 F<VMS_AXP>, and I<Extname> is the name of the extension, with
134 each C<::> translated to C<.>). However, it can be manually
135 placed in any of several locations:
136 - the F<[.Lib.Auto.I<Extname>]> subdirectory of one of
137 the directories in C<@INC>, or
138 - one of the directories in C<@INC>, or
139 - a directory which the extensions Perl library module
140 passes to the DynaLoader when asking it to map
141 the shareable image, or
142 - F<Sys$Share> or F<Sys$Library>.
143 If the shareable image isn't in any of these places, you'll need
144 to define a logical name I<Extshortname>, where I<Extshortname>
145 is the portion of the extension's name after the last C<::>, which
146 translates to the full file specification of the shareable image.
150 Directions for building and installing Perl 5 can be found in
151 the file F<ReadMe.VMS> in the main source directory of the
154 =head1 File specifications
156 We have tried to make Perl aware of both VMS-style and Unix-
157 style file specifications wherever possible. You may use
158 either style, or both, on the command line and in scripts,
159 but you may not combine the two styles within a single fle
160 specfication. Filenames are, of course, still case-
161 insensitive. For consistency, most Perl routines return
162 filespecs using lower case latters only, regardless of the
163 case used in the arguments passed to them. (This is true
164 only when running under VMS; Perl respects the case-
165 sensitivity of OSs like Unix.)
167 We've tried to minimize the dependence of Perl library
168 modules on Unix syntax, but you may find that some of these,
169 as well as some scripts written for Unix systems, will
170 require that you use Unix syntax, since they will assume that
171 '/' is the directory separator, etc. If you find instances
172 of this in the Perl distribution itself, please let us know,
173 so we can try to work around them.
175 =head1 Command line redirection
177 Perl for VMS supports redirection of input and output on the
178 command line, using a subset of Bourne shell syntax:
179 <F<file> reads stdin from F<file>,
180 >F<file> writes stdout to F<file>,
181 >>F<file> appends stdout to F<file>,
182 2>F<file> writes stderr to F<file>, and
183 2>>F<file> appends stderr to F<file>.
185 In addition, output may be piped to a subprocess, using the
186 character '|'. Anything after this character on the command
187 line is passed to a subprocess for execution; the subprocess
188 takes the output of Perl as its input.
190 Finally, if the command line ends with '&', the entire
191 command is run in the background as an asynchronous
196 Input and output pipes to Perl filehandles are supported; the
197 "file name" is passed to lib$spawn() for asynchronous
198 execution. You should be careful to close any pipes you have
199 opened in a Perl script, lest you leave any "orphaned"
200 subprocesses around when Perl exits.
202 You may also use backticks to invoke a DCL subprocess, whose
203 output is used as the return value of the expression. The
204 string between the backticks is passed directly to lib$spawn
205 as the command to execute. In this case, Perl will wait for
206 the subprocess to complete before continuing.
208 =head1 Wildcard expansion
210 File specifications containing wildcards are allowed both on
211 the command line and within Perl globs (e.g. <C<*.c>>). If
212 the wildcard filespec uses VMS syntax, the resultant
213 filespecs will follow VMS syntax; if a Unix-style filespec is
214 passed in, Unix-style filespecs will be returned..
216 If the wildcard filespec contains a device or directory
217 specification, then the resultant filespecs will also contain
218 a device and directory; otherwise, device and directory
219 information are removed. VMS-style resultant filespecs will
220 contain a full device and directory, while Unix-style
221 resultant filespecs will contain only as much of a directory
222 path as was present in the input filespec. For example, if
223 your default directory is Perl_Root:[000000], the expansion
224 of C<[.t]*.*> will yield filespecs like
225 "perl_root:[t]base.dir", while the expansion of C<t/*/*> will
226 yield filespecs like "t/base.dir". (This is done to match
227 the behavior of glob expansion performed by Unix shells.)
229 Similarly, the resultant filespec will the file version only
230 if one was present in the input filespec.
232 =head1 PERL5LIB and PERLLIB
234 The PERL5LIB and PERLLIB logical names work as
235 documented L<perl>, except that the element
236 separator is '|' instead of ':'. The directory
237 specifications may use either VMS or Unix syntax.
241 Reading the elements of the %ENV array returns the
242 translation of the logical name specified by the key,
243 according to the normal search order of access modes and
244 logical name tables. In addition, the keys C<home>,
245 C<path>,C<term>, and C<user> return the CRTL "environment
246 variables" of the same names. The key C<default> returns the
247 current default device and directory specification.
249 Setting an element of %ENV defines a supervisor-mode logical
250 name in the process logical name table. C<Undef>ing or
251 C<delete>ing an element of %ENV deletes the equivalent user-
252 mode or supervisor-mode logical name from the process logical
253 name table. If you use C<undef>, the %ENV element remains
254 empty. If you use C<delete>, another attempt is made at
255 logical name translation after the deletion, so an inner-mode
256 logical name or a name in another logical name table will
257 replace the logical name just deleted.
259 In all operations on %ENV, the key string is treated as if it
260 were entirely uppercase, regardless of the case actually
261 specified in the Perl expression.
263 =head1 Perl functions
265 As of the time this document was last revised, the following
266 Perl functions were implemented in the VMS port of Perl
267 (functions marked with * are discussed in more detail below):
269 file tests*, abs, alarm, atan, binmode*, bless,
270 caller, chdir, chmod, chown, chomp, chop, chr,
271 close, closedir, cos, defined, delete, die, do,
272 each, endpwent, eof, eval, exec*, exists, exit,
273 exp, fileno, fork*, getc, getpwent*, getpwnam*,
274 getpwuid*, glob, gmtime*, goto, grep, hex, import,
275 index, int, join, keys, kill*, last, lc, lcfirst,
276 length, local, localtime, log, m//, map, mkdir, my,
277 next, no, oct, open, opendir, ord, pack, pipe, pop,
278 pos, print, printf, push, q//, qq//, qw//, qx//,
279 quotemeta, rand, read, readdir, redo, ref, rename,
280 require, reset, return, reverse, rewinddir, rindex,
281 rmdir, s///, scalar, seek, seekdir, select(internal),
282 select (system call)*, setpwent, shift, sin, sleep,
283 sort, splice, split, sprintf, sqrt, srand, stat,
284 study, substr, sysread, system*, syswrite, tell,
285 telldir, tie, time, times*, tr///, uc, ucfirst, umask,
286 undef, unlink*, unpack, untie, unshift, use, utime*,
287 values, vec, wait, waitpid*, wantarray, warn, write, y///
289 The following functions were not implemented in the VMS port,
290 and calling them produces a fatal error (usually) or
291 undefined behavior (rarely, we hope):
293 chroot, crypt, dbmclose, dbmopen, dump, fcntl,
294 flock, getlogin, getpgrp, getppid, getpriority,
295 getgrent, kill, getgrgid, getgrnam, setgrent,
296 endgrent, ioctl, link, lstst, msgctl, msgget,
297 msgsend, msgrcv, readlink, select(system call),
298 semctl, semget, semop, setpgrp, setpriority, shmctl,
299 shmget, shmread, shmwrite, socketpair, symlink,
302 The following functions may or may not be implemented,
303 depending on what type of socket support you've built into
305 accept, bind, connect, getpeername,
306 gethostbyname, getnetbyname, getprotobyname,
307 getservbyname, gethostbyaddr, getnetbyaddr,
308 getprotobynumber, getservbyport, gethostent,
309 getnetent, getprotoent, getservent, sethostent,
310 setnetent, setprotoent, setservent, endhostent,
311 endnetent, endprotoent, endservent, getsockname,
312 getsockopt, listen, recv, send, setsockopt,
318 The tests C<-b>, C<-B>, C<-c>, C<-C>, C<-d>, C<-e>, C<-f>,
319 C<-o>, C<-M>, C<-s>, C<-S>, C<-t>, C<-T>, and C<-z> work as
320 advertised. The return values for C<-r>, C<-w>, and C<-x>
321 tell you whether you can actually access the file; this may
322 not reflect the UIC-based file protections. Since real and
323 effective UIC don't differ under VMS, C<-O>, C<-R>, C<-W>,
324 and C<-X> are equivalent to C<-o>, C<-r>, C<-w>, and C<-x>.
325 Similarly, several other tests, including C<-A>, C<-g>, C<-k>,
326 C<-l>, C<-p>, and C<-u>, aren't particularly meaningful under
327 VMS, and the values returned by these tests reflect whatever
328 your CRTL C<stat()> routine does to the equivalent bits in the
329 st_mode field. Finally, C<-d> returns true if passed a device
330 specification without an explicit directory (e.g. C<DUA1:>), as
331 well as if passed a directory.
333 =item binmode FILEHANDLE
335 The C<binmode> operator has no effect under VMS. It will
336 return TRUE whenever called, but will not affect I/O
337 operations on the filehandle given as its argument.
341 The C<exec> operator behaves in one of two different ways.
342 If called after a call to C<fork>, it will invoke the CRTL
343 C<execv()> routine, passing its arguments to the subprocess
344 created by C<fork> for execution. In this case, it is
345 subject to all limitations that affect C<execv()>. (In
346 particular, this usually means that the command executed in
347 the subprocess must be an image compiled from C source code,
348 and that your options for passing file descriptors and signal
349 handlers to the subprocess are limited.)
351 If the call to C<exec> does not follow a call to C<fork>, it
352 will cause Perl to exit, and to invoke the command given as
353 an argument to C<exec> via C<lib$do_command>. If the argument
354 begins with a '$' (other than as part of a filespec), then it
355 is executed as a DCL command. Otherwise, the first token on
356 the command line is treated as the filespec of an image to
357 run, and an attempt is made to invoke it (using F<.Exe> and
358 the process defaults to expand the filespec) and pass the
359 rest of C<exec>'s argument to it as parameters.
361 You can use C<exec> in both ways within the same script, as
362 long as you call C<fork> and C<exec> in pairs. Perl
363 keeps track of how many times C<fork> and C<exec> have been
364 called, and will call the CRTL C<execv()> routine if there have
365 previously been more calls to C<fork> than to C<exec>.
369 The C<fork> operator works in the same way as the CRTL
370 C<vfork()> routine, which is quite different under VMS than
371 under Unix. Specifically, while C<fork> returns 0 after it
372 is called and the subprocess PID after C<exec> is called, in
373 both cases the thread of execution is within the parent
374 process, so there is no opportunity to perform operations in
375 the subprocess before calling C<exec>.
377 In general, the use of C<fork> and C<exec> to create
378 subprocess is not recommended under VMS; wherever possible,
379 use the C<system> operator or piped filehandles instead.
385 These operators obtain the information described in L<perlfunc>,
386 if you have the privileges necessary to retrieve the named user's
387 UAF information via C<sys$getuai>. If not, then only the C<$name>,
388 C<$uid>, and C<$gid> items are returned. The C<$dir> item contains
389 the login directory in VMS syntax, while the C<$comment> item
390 contains the login directory in Unix syntax. The C<$gcos> item
391 contains the owner field from the UAF record. The C<$quota>
396 The C<gmtime> operator will function properly if you have a
397 working CRTL C<gmtime()> routine, or if the logical name
398 SYS$TIMEZONE_DIFFERENTIAL is defined as the number of seconds
399 which must be added to UTC to yield local time. (This logical
400 name is defined automatically if you are running a version of
401 VMS with built-in UTC support.) If neither of these cases is
402 true, a warning message is printed, and C<undef> is returned.
406 In most cases, C<kill> kill is implemented via the CRTL's C<kill()>
407 function, so it will behave according to that function's
408 documentation. If you send a SIGKILL, however, the $DELPRC system
409 service is is called directly. This insures that the target
410 process is actually deleted, if at all possible. (The CRTL's C<kill()>
411 function is presently implemented via $FORCEX, which is ignored by
412 supervisor-mode images like DCL.)
414 Also, negative signal values don't do anything special under
415 VMS; they're just converted to the corresponding positive value.
417 =item select (system call)
419 If Perl was not built with socket support, the system call
420 version of C<select> is not available at all. If socket
421 support is present, then the system call version of
422 C<select> functions only for file descriptors attached
423 to sockets. It will not provide information about regular
424 files or pipes, since the CRTL C<select()> routine does not
425 provide this functionality.
429 Since VMS keeps track of files according to a different scheme
430 than Unix, it's not really possible to represent the file's ID
431 in the C<st_dev> and C<st_ino> fields of a C<struct stat>. Perl
432 tries its best, though, and the values it uses are pretty unlikely
433 to be the same for two different files. We can't guarantee this,
434 though, so caveat scriptor.
438 The C<system> operator creates a subprocess, and passes its
439 arguments to the subprocess for execution as a DCL command.
440 Since the subprocess is created directly via C<lib$spawn()>, any
441 valid DCL command string may be specified. If LIST consists
442 of the empty string, C<system> spawns an interactive DCL subprocess,
443 in the same fashion as typiing B<SPAWN> at the DCL prompt.
444 Perl waits for the subprocess to complete before continuing
445 execution in the current process.
449 The array returned by the C<times> operator is divided up
450 according to the same rules the CRTL C<times()> routine.
451 Therefore, the "system time" elements will always be 0, since
452 there is no difference between "user time" and "system" time
453 under VMS, and the time accumulated by subprocess may or may
454 not appear separately in the "child time" field, depending on
455 whether L<times> keeps track of subprocesses separately. Note
456 especially that the VAXCRTL (at least) keeps track only of
457 subprocesses spawned using L<fork> and L<exec>; it will not
458 accumulate the times of suprocesses spawned via pipes, L<system>,
463 C<unlink> will delete the highest version of a file only; in
464 order to delete all versions, you need to say
465 1 while (unlink LIST);
466 You may need to make this change to scripts written for a
467 Unix system which expect that after a call to C<unlink>,
468 no files with the names passed to C<unlink> will exist.
469 (Note: This can be changed at compile time; if you
470 C<use Config> and C<$Config{'d_unlink_all_versions'}> is
471 C<define>, then C<unlink> will delete all versions of a
472 file on the first call.)
474 C<unlink> will delete a file if at all possible, even if it
475 requires changing file protection (though it won't try to
476 change the protection of the parent directory). You can tell
477 whether you've got explicit delete access to a file by using the
478 C<VMS::Filespec::candelete> operator. For instance, in order
479 to delete only files to which you have delete access, you could
484 next unless VMS::Filespec::candelete($file);
485 $num += unlink $file;
489 Finally, if C<unlink> has to change the file protection to
490 delete the file, and you interrupt it in midstream, the file
491 may be left intact, but with a changed ACL allowing you delete
496 Since ODS-2, the VMS file structure for disk files, does not keep
497 track of access times, this operator changes only the modification
498 time of the file (VMS revision date).
500 =item waitpid PID,FLAGS
502 If PID is a subprocess started by a piped L<open>, C<waitpid>
503 will wait for that subprocess, and return its final
504 status value. If PID is a subprocess created in some other way
505 (e.g. SPAWNed before Perl was invoked), or is not a subprocess of
506 the current process, C<waitpid> will check once per second whether
507 the process has completed, and when it has, will return 0. (If PID
508 specifies a process that isn't a subprocess of the current process,
509 and you invoked Perl with the C<-w> switch, a warning will be issued.)
511 The FLAGS argument is ignored in all cases.
515 This document was last updated on 16-Dec-1994, for Perl 5,
520 Charles Bailey bailey@genetics.upenn.edu