perl 5.003_06: t/op/each.t
[p5sagit/p5-mst-13.2.git] / vms / perlvms.pod
CommitLineData
e518068a 1=head1 NAME
2
3perlvms - VMS-specific documentation for Perl
4
5=head1 DESCRIPTION
a0d0e21e 6
748a9306 7Gathered below are notes describing details of Perl 5's
8behavior on VMS. They are a supplement to the regular Perl 5
9documentation, so we have focussed on the ways in which Perl
105 functions differently under VMS than it does under Unix,
11and on the interactions between Perl and the rest of the
a0d0e21e 12operating system. We haven't tried to duplicate complete
748a9306 13descriptions of Perl features from the main Perl
a0d0e21e 14documentation, which can be found in the F<[.pod]>
748a9306 15subdirectory of the Perl distribution.
a0d0e21e 16
17We hope these notes will save you from confusion and lost
748a9306 18sleep when writing Perl scripts on VMS. If you find we've
a0d0e21e 19missed something you think should appear here, please don't
20hesitate to drop a line to vmsperl@genetics.upenn.edu.
21
4e592037 22=head1 Installation
23
24Directions for building and installing Perl 5 can be found in
25the file F<README.vms> in the main source directory of the
26Perl distribution..
27
e518068a 28=head1 Organization of Perl Images
748a9306 29
e518068a 30=head2 Core Images
748a9306 31
32During the installation process, three Perl images are produced.
33F<Miniperl.Exe> is an executable image which contains all of
34the basic functionality of Perl, but cannot take advantage of
35Perl extensions. It is used to generate several files needed
36to build the complete Perl and various extensions. Once you've
37finished installing Perl, you can delete this image.
38
39Most of the complete Perl resides in the shareable image
40F<PerlShr.Exe>, which provides a core to which the Perl executable
41image and all Perl extensions are linked. You should place this
42image in F<Sys$Share>, or define the logical name F<PerlShr> to
43translate to the full file specification of this image. It should
44be world readable. (Remember that if a user has execute only access
45to F<PerlShr>, VMS will treat it as if it were a privileged shareable
46image, and will therefore require all downstream shareable images to be
47INSTALLed, etc.)
48
49
50Finally, F<Perl.Exe> is an executable image containing the main
51entry point for Perl, as well as some initialization code. It
52should be placed in a public directory, and made world executable.
53In order to run Perl with command line arguments, you should
54define a foreign command to invoke this image.
55
56=head2 Perl Extensions
57
58Perl extensions are packages which provide both XS and Perl code
59to add new functionality to perl. (XS is a meta-language which
60simplifies writing C code which interacts with Perl, see
61L<perlapi> for more details.) The Perl code for an
62extension is treated like any other library module - it's
63made available in your script through the appropriate
64C<use> or C<require> statement, and usually defines a Perl
65package containing the extension.
66
67The portion of the extension provided by the XS code may be
68connected to the rest of Perl in either of two ways. In the
69B<static> configuration, the object code for the extension is
70linked directly into F<PerlShr.Exe>, and is initialized whenever
71Perl is invoked. In the B<dynamic> configuration, the extension's
72machine code is placed into a separate shareable image, which is
73mapped by Perl's DynaLoader when the extension is C<use>d or
74C<require>d in your script. This allows you to maintain the
75extension as a separate entity, at the cost of keeping track of the
76additional shareable image. Most extensions can be set up as either
77static or dynamic.
78
79The source code for an extension usually resides in its own
80directory. At least three files are generally provided:
81I<Extshortname>F<.xs> (where I<Extshortname> is the portion of
82the extension's name following the last C<::>), containing
83the XS code, I<Extshortname>F<.pm>, the Perl library module
84for the extension, and F<Makefile.PL>, a Perl script which uses
85the C<MakeMaker> library modules supplied with Perl to generate
86a F<Descrip.MMS> file for the extension.
87
e518068a 88=head2 Installing static extensions
748a9306 89
90Since static extensions are incorporated directly into
91F<PerlShr.Exe>, you'll have to rebuild Perl to incorporate a
92new extension. You should edit the main F<Descrip.MMS> or F<Makefile>
93you use to build Perl, adding the extension's name to the C<ext>
94macro, and the extension's object file to the C<extobj> macro.
95You'll also need to build the extension's object file, either
96by adding dependencies to the main F<Descrip.MMS>, or using a
97separate F<Descrip.MMS> for the extension. Then, rebuild
98F<PerlShr.Exe> to incorporate the new code.
99
100Finally, you'll need to copy the extension's Perl library
101module to the F<[.>I<Extname>F<]> subdirectory under one
102of the directories in C<@INC>, where I<Extname> is the name
103of the extension, with all C<::> replaced by C<.> (e.g.
104the library module for extension Foo::Bar would be copied
105to a F<[.Foo.Bar]> subdirectory).
106
e518068a 107=head2 Installing dynamic extensions
108
109In general, the distributed kit for a Perl extension includes
110a file named Makefile.PL, which is a Perl program which is used
111to create a F<Descrip.MMS> file which can be used to build and
112install the files required by the extension. The kit should be
c07a80fd 113unpacked into a directory tree B<not> under the main Perl source
e518068a 114directory, and the procedure for building the extension is simply
115
e518068a 116 $ perl Makefile.PL ! Create Descrip.MMS
117 $ mmk ! Build necessary files
118 $ mmk test ! Run test code, if supplied
119 $ mmk install ! Install into public Perl tree
120
c07a80fd 121I<N.B.> The procedure by which extensions are built and
122tested creates several levels (at least 4) under the
123directory in which the extension's source files live.
124For this reason, you shouldn't nest the source directory
125too deeply in your directory structure, lest you eccedd RMS'
126maximum of 8 levels of subdirectory in a filespec. (You
127can use rooted logical names to get another 8 levels of
128nesting, if you can't place the files near the top of
129the physical directory structure.)
e518068a 130
131VMS support for this process in the current release of Perl
132is sufficient to handle most extensions. However, it does
133not yet recognize extra libraries required to build shareable
134images which are part of an extension, so these must be added
135to the linker options file for the extension by hand. For
136instance, if the F<PGPLOT> extension to Perl requires the
137F<PGPLOTSHR.EXE> shareable image in order to properly link
138the Perl extension, then the line C<PGPLOTSHR/Share> must
139be added to the linker options file F<PGPLOT.Opt> produced
140during the build process for the Perl extension.
141
142By default, the shareable image for an extension is placed
4e592037 143in the F<[.Lib.Auto.>I<Arch>.I<Extname>F<]> directory of the
e518068a 144installed Perl directory tree (where I<Arch> is F<VMS_VAX> or
4e592037 145F<VMS_AXP>, followed by the Perl version number, and I<Extname>
146is the name of the extension, with each C<::> translated to C<.>).
147However, it can be manually placed in any of several locations:
148 - the F<[.Lib.Auto.>I<Extname>F<]> subdirectory of one of
e518068a 149 the directories in C<@INC>, or
748a9306 150 - one of the directories in C<@INC>, or
151 - a directory which the extensions Perl library module
152 passes to the DynaLoader when asking it to map
153 the shareable image, or
154 - F<Sys$Share> or F<Sys$Library>.
155If the shareable image isn't in any of these places, you'll need
156to define a logical name I<Extshortname>, where I<Extshortname>
157is the portion of the extension's name after the last C<::>, which
158translates to the full file specification of the shareable image.
159
4e592037 160=head1 File specifications
748a9306 161
4e592037 162=head2 Syntax
a0d0e21e 163
748a9306 164We have tried to make Perl aware of both VMS-style and Unix-
a0d0e21e 165style file specifications wherever possible. You may use
166either style, or both, on the command line and in scripts,
167but you may not combine the two styles within a single fle
1c9f8daa 168specification. VMS Perl interprets Unix pathnames in much
169the same way as the CRTL (I<e.g.> the first component of
170an absolute path is read as the device name for the
171VMS file specification). There are a set of functions
172provided in the C<VMS::Filespec> package for explicit
173interconversion between VMS and Unix syntax; its
174documentation provides more details.
175
176Filenames are, of course, still case-insensitive. For
177consistency, most Perl routines return filespecs using
178lower case letters only, regardless of the case used in
179the arguments passed to them. (This is true only when
180running under VMS; Perl respects the case-sensitivity
181of OSs like Unix.)
a0d0e21e 182
748a9306 183We've tried to minimize the dependence of Perl library
a0d0e21e 184modules on Unix syntax, but you may find that some of these,
185as well as some scripts written for Unix systems, will
186require that you use Unix syntax, since they will assume that
4e592037 187'/' is the directory separator, I<etc.> If you find instances
748a9306 188of this in the Perl distribution itself, please let us know,
a0d0e21e 189so we can try to work around them.
190
4e592037 191=head2 Wildcard expansion
192
193File specifications containing wildcards are allowed both on
194the command line and within Perl globs (e.g. <CE<lt>*.cE<gt>>). If
195the wildcard filespec uses VMS syntax, the resultant
196filespecs will follow VMS syntax; if a Unix-style filespec is
197passed in, Unix-style filespecs will be returned.
198
199If the wildcard filespec contains a device or directory
200specification, then the resultant filespecs will also contain
201a device and directory; otherwise, device and directory
202information are removed. VMS-style resultant filespecs will
203contain a full device and directory, while Unix-style
204resultant filespecs will contain only as much of a directory
205path as was present in the input filespec. For example, if
206your default directory is Perl_Root:[000000], the expansion
207of C<[.t]*.*> will yield filespecs like
208"perl_root:[t]base.dir", while the expansion of C<t/*/*> will
209yield filespecs like "t/base.dir". (This is done to match
210the behavior of glob expansion performed by Unix shells.)
211
212Similarly, the resultant filespec will contain the file version
213only if one was present in the input filespec.
214
215=head2 Pipes
216
217Input and output pipes to Perl filehandles are supported; the
218"file name" is passed to lib$spawn() for asynchronous
219execution. You should be careful to close any pipes you have
220opened in a Perl script, lest you leave any "orphaned"
221subprocesses around when Perl exits.
222
223You may also use backticks to invoke a DCL subprocess, whose
224output is used as the return value of the expression. The
225string between the backticks is passed directly to lib$spawn
226as the command to execute. In this case, Perl will wait for
227the subprocess to complete before continuing.
228
229=head1 PERL5LIB and PERLLIB
230
231The PERL5LIB and PERLLIB logical names work as documented L<perl>,
232except that the element separator is '|' instead of ':'. The
233directory specifications may use either VMS or Unix syntax.
234
235=head1 Command line
236
237=head2 I/O redirection and backgrounding
a0d0e21e 238
239Perl for VMS supports redirection of input and output on the
240command line, using a subset of Bourne shell syntax:
241 <F<file> reads stdin from F<file>,
242 >F<file> writes stdout to F<file>,
243 >>F<file> appends stdout to F<file>,
748a9306 244 2>F<file> writes stderr to F<file>, and
a0d0e21e 245 2>>F<file> appends stderr to F<file>.
246
247In addition, output may be piped to a subprocess, using the
248character '|'. Anything after this character on the command
249line is passed to a subprocess for execution; the subprocess
748a9306 250takes the output of Perl as its input.
a0d0e21e 251
252Finally, if the command line ends with '&', the entire
253command is run in the background as an asynchronous
254subprocess.
255
4e592037 256=head2 Command line switches
a0d0e21e 257
4e592037 258The following command line switches behave differently under
259VMS than described in L<perlrun>. Note also that in order
260to pass uppercase switches to Perl, you need to enclose
261them in double-quotes on the command line, since the CRTL
262downcases all unquoted strings.
a0d0e21e 263
edc7bc49 264=item -i
265
266If the C<-i> switch is present but no extension for a backup
267copy is given, then inplace editing creates a new version of
268a file; the existing copy is not deleted. (Note that if
269an extension is given, an existing file is renamed to the backup
270file, as is the case under other operating systems, so it does
271not remain as a previous version under the original filename.)
272
4e592037 273=item -S
a0d0e21e 274
4e592037 275If the C<-S> switch is present I<and> the script name does
276not contain a directory, then Perl translates the logical
277name DCL$PATH as a searchlist, using each translation as
278a directory in which to look for the script. In addition,
279if no file type is specified, Perl looks in each directory
280for a file matching the name specified, with a blank type,
281a type of F<.pl>, and a type of F<.com>, in that order.
a0d0e21e 282
4e592037 283=item -u
748a9306 284
4e592037 285The C<-u> switch causes the VMS debugger to be invoked
286after the Perl program is compiled, but before it has
287run. It does not create a core dump file.
748a9306 288
748a9306 289=head1 Perl functions
a0d0e21e 290
291As of the time this document was last revised, the following
748a9306 292Perl functions were implemented in the VMS port of Perl
a0d0e21e 293(functions marked with * are discussed in more detail below):
294
295 file tests*, abs, alarm, atan, binmode*, bless,
296 caller, chdir, chmod, chown, chomp, chop, chr,
c07a80fd 297 close, closedir, cos, crypt*, defined, delete,
4e592037 298 die, do, dump*, each, endpwent, eof, eval, exec*,
299 exists, exit, exp, fileno, fork*, getc, getlogin,
300 getpwent*, getpwnam*, getpwuid*, glob, gmtime*, goto,
301 grep, hex, import, index, int, join, keys, kill*,
302 last, lc, lcfirst, length, local, localtime, log, m//,
303 map, mkdir, my, next, no, oct, open, opendir, ord, pack,
c07a80fd 304 pipe, pop, pos, print, printf, push, q//, qq//, qw//,
305 qx//, quotemeta, rand, read, readdir, redo, ref, rename,
a0d0e21e 306 require, reset, return, reverse, rewinddir, rindex,
e518068a 307 rmdir, s///, scalar, seek, seekdir, select(internal),
308 select (system call)*, setpwent, shift, sin, sleep,
309 sort, splice, split, sprintf, sqrt, srand, stat,
310 study, substr, sysread, system*, syswrite, tell,
311 telldir, tie, time, times*, tr///, uc, ucfirst, umask,
312 undef, unlink*, unpack, untie, unshift, use, utime*,
313 values, vec, wait, waitpid*, wantarray, warn, write, y///
a0d0e21e 314
315The following functions were not implemented in the VMS port,
316and calling them produces a fatal error (usually) or
317undefined behavior (rarely, we hope):
318
4e592037 319 chroot, dbmclose, dbmopen, fcntl, flock,
c07a80fd 320 getpgrp, getppid, getpriority, getgrent, getgrgid,
321 getgrnam, setgrent, endgrent, ioctl, link, lstat,
322 msgctl, msgget, msgsend, msgrcv, readlink, semctl,
323 semget, semop, setpgrp, setpriority, shmctl, shmget,
324 shmread, shmwrite, socketpair, symlink, syscall, truncate
a0d0e21e 325
326The following functions may or may not be implemented,
327depending on what type of socket support you've built into
748a9306 328your copy of Perl:
4e592037 329
a0d0e21e 330 accept, bind, connect, getpeername,
331 gethostbyname, getnetbyname, getprotobyname,
332 getservbyname, gethostbyaddr, getnetbyaddr,
333 getprotobynumber, getservbyport, gethostent,
334 getnetent, getprotoent, getservent, sethostent,
335 setnetent, setprotoent, setservent, endhostent,
336 endnetent, endprotoent, endservent, getsockname,
c07a80fd 337 getsockopt, listen, recv, select(system call)*,
338 send, setsockopt, shutdown, socket
a0d0e21e 339
340
341=item File tests
342
748a9306 343The tests C<-b>, C<-B>, C<-c>, C<-C>, C<-d>, C<-e>, C<-f>,
344C<-o>, C<-M>, C<-s>, C<-S>, C<-t>, C<-T>, and C<-z> work as
345advertised. The return values for C<-r>, C<-w>, and C<-x>
346tell you whether you can actually access the file; this may
347not reflect the UIC-based file protections. Since real and
348effective UIC don't differ under VMS, C<-O>, C<-R>, C<-W>,
349and C<-X> are equivalent to C<-o>, C<-r>, C<-w>, and C<-x>.
350Similarly, several other tests, including C<-A>, C<-g>, C<-k>,
351C<-l>, C<-p>, and C<-u>, aren't particularly meaningful under
352VMS, and the values returned by these tests reflect whatever
353your CRTL C<stat()> routine does to the equivalent bits in the
354st_mode field. Finally, C<-d> returns true if passed a device
355specification without an explicit directory (e.g. C<DUA1:>), as
356well as if passed a directory.
357
4e592037 358Note: Some sites have reported problems when using the file-access
359tests (C<-r>, C<-w>, and C<-x>) on files accessed via DEC's DFS.
360Specifically, since DFS does not currently provide access to the
361extended file header of files on remote volumes, attempts to
362examine the ACL fail, and the file tests will return false,
363with C<$!> indicating that the file does not exist. You can
364use C<stat> on these files, since that checks UIC-based protection
365only, and then manually check the appropriate bits, as defined by
366your C compiler's F<stat.h>, in the mode value it returns, if you
367need an approximation of the file's protections.
368
748a9306 369=item binmode FILEHANDLE
370
1c9f8daa 371The C<binmode> operator will attempt to insure that no translation
372of carriage control occurs on input from or output to this filehandle.
373Since this involves reopening the file and then restoring its
374file position indicator, if this function returns FALSE, the
375underlying filehandle may no longer point to an open file, or may
376point to a different position in the file than before C<binmode>
377was called.
378
379Note that C<binmode> is generally not necessary when using normal
380filehandles; it is provided so that you can control I/O to existing
381record-structured files when necessary. You can also use the
382C<vmsfopen> function in the VMS::Stdio extension to gain finer
383control of I/O to files and devices with different record structures.
a0d0e21e 384
c07a80fd 385=item crypt PLAINTEXT, USER
386
387The C<crypt> operator uses the C<sys$hash_password> system
388service to generate the hashed representation of PLAINTEXT.
389If USER is a valid username, the algorithm and salt values
390are taken from that user's UAF record. If it is not, then
391the preferred algorithm and a salt of 0 are used. The
392quadword encrypted value is returned as an 8-character string.
393
394The value returned by C<crypt> may be compared against
395the encrypted password from the UAF returned by the C<getpw*>
396functions, in order to authenticate users. If you're
397going to do this, remember that the encrypted password in
398the UAF was generated using uppercase username and
399password strings; you'll have to upcase the arguments to
400C<crypt> to insure that you'll get the proper value:
401
402 sub validate_passwd {
403 my($user,$passwd) = @_;
404 my($pwdhash);
405 if ( !($pwdhash = (getpwnam($user))[1]) ||
406 $pwdhash ne crypt("\U$passwd","\U$name") ) {
407 intruder_alert($name);
408 }
409 return 1;
410 }
411
4e592037 412=item dump
413
414Rather than causing Perl to abort and dump core, the C<dump>
415operator invokes the VMS debugger. If you continue to
416execute the Perl program under the debugger, control will
417be transferred to the label specified as the argument to
418C<dump>, or, if no label was specified, back to the
419beginning of the program. All other state of the program
420(I<e.g.> values of variables, open file handles) are not
421affected by calling C<dump>.
422
748a9306 423=item exec LIST
a0d0e21e 424
748a9306 425The C<exec> operator behaves in one of two different ways.
426If called after a call to C<fork>, it will invoke the CRTL
427C<execv()> routine, passing its arguments to the subprocess
428created by C<fork> for execution. In this case, it is
429subject to all limitations that affect C<execv()>. (In
a0d0e21e 430particular, this usually means that the command executed in
431the subprocess must be an image compiled from C source code,
432and that your options for passing file descriptors and signal
433handlers to the subprocess are limited.)
434
748a9306 435If the call to C<exec> does not follow a call to C<fork>, it
436will cause Perl to exit, and to invoke the command given as
437an argument to C<exec> via C<lib$do_command>. If the argument
a0d0e21e 438begins with a '$' (other than as part of a filespec), then it
439is executed as a DCL command. Otherwise, the first token on
440the command line is treated as the filespec of an image to
441run, and an attempt is made to invoke it (using F<.Exe> and
442the process defaults to expand the filespec) and pass the
748a9306 443rest of C<exec>'s argument to it as parameters.
a0d0e21e 444
748a9306 445You can use C<exec> in both ways within the same script, as
446long as you call C<fork> and C<exec> in pairs. Perl
447keeps track of how many times C<fork> and C<exec> have been
448called, and will call the CRTL C<execv()> routine if there have
449previously been more calls to C<fork> than to C<exec>.
a0d0e21e 450
451=item fork
452
748a9306 453The C<fork> operator works in the same way as the CRTL
454C<vfork()> routine, which is quite different under VMS than
455under Unix. Specifically, while C<fork> returns 0 after it
456is called and the subprocess PID after C<exec> is called, in
a0d0e21e 457both cases the thread of execution is within the parent
458process, so there is no opportunity to perform operations in
748a9306 459the subprocess before calling C<exec>.
a0d0e21e 460
748a9306 461In general, the use of C<fork> and C<exec> to create
a0d0e21e 462subprocess is not recommended under VMS; wherever possible,
748a9306 463use the C<system> operator or piped filehandles instead.
464
465=item getpwent
c07a80fd 466
748a9306 467=item getpwnam
c07a80fd 468
748a9306 469=item getpwuid
470
471These operators obtain the information described in L<perlfunc>,
472if you have the privileges necessary to retrieve the named user's
473UAF information via C<sys$getuai>. If not, then only the C<$name>,
474C<$uid>, and C<$gid> items are returned. The C<$dir> item contains
475the login directory in VMS syntax, while the C<$comment> item
476contains the login directory in Unix syntax. The C<$gcos> item
477contains the owner field from the UAF record. The C<$quota>
478item is not used.
a0d0e21e 479
e518068a 480=item gmtime
481
482The C<gmtime> operator will function properly if you have a
483working CRTL C<gmtime()> routine, or if the logical name
484SYS$TIMEZONE_DIFFERENTIAL is defined as the number of seconds
485which must be added to UTC to yield local time. (This logical
486name is defined automatically if you are running a version of
487VMS with built-in UTC support.) If neither of these cases is
488true, a warning message is printed, and C<undef> is returned.
489
490=item kill
491
492In most cases, C<kill> kill is implemented via the CRTL's C<kill()>
493function, so it will behave according to that function's
494documentation. If you send a SIGKILL, however, the $DELPRC system
495service is is called directly. This insures that the target
496process is actually deleted, if at all possible. (The CRTL's C<kill()>
497function is presently implemented via $FORCEX, which is ignored by
498supervisor-mode images like DCL.)
499
500Also, negative signal values don't do anything special under
501VMS; they're just converted to the corresponding positive value.
502
503=item select (system call)
504
505If Perl was not built with socket support, the system call
506version of C<select> is not available at all. If socket
507support is present, then the system call version of
508C<select> functions only for file descriptors attached
509to sockets. It will not provide information about regular
510files or pipes, since the CRTL C<select()> routine does not
511provide this functionality.
512
748a9306 513=item stat EXPR
a0d0e21e 514
748a9306 515Since VMS keeps track of files according to a different scheme
516than Unix, it's not really possible to represent the file's ID
517in the C<st_dev> and C<st_ino> fields of a C<struct stat>. Perl
518tries its best, though, and the values it uses are pretty unlikely
519to be the same for two different files. We can't guarantee this,
520though, so caveat scriptor.
521
522=item system LIST
523
524The C<system> operator creates a subprocess, and passes its
a0d0e21e 525arguments to the subprocess for execution as a DCL command.
e518068a 526Since the subprocess is created directly via C<lib$spawn()>, any
748a9306 527valid DCL command string may be specified. If LIST consists
528of the empty string, C<system> spawns an interactive DCL subprocess,
529in the same fashion as typiing B<SPAWN> at the DCL prompt.
530Perl waits for the subprocess to complete before continuing
531execution in the current process.
a0d0e21e 532
1c9f8daa 533=item time
534
535The value returned by C<time> is the offset in seconds from
53601-JAN-1970 00:00:00 (just like the CRTL's times() routine), in order
537to make life easier for code coming in from the POSIX/Unix world.
538
a0d0e21e 539=item times
540
748a9306 541The array returned by the C<times> operator is divided up
542according to the same rules the CRTL C<times()> routine.
a0d0e21e 543Therefore, the "system time" elements will always be 0, since
544there is no difference between "user time" and "system" time
545under VMS, and the time accumulated by subprocess may or may
546not appear separately in the "child time" field, depending on
748a9306 547whether L<times> keeps track of subprocesses separately. Note
548especially that the VAXCRTL (at least) keeps track only of
549subprocesses spawned using L<fork> and L<exec>; it will not
550accumulate the times of suprocesses spawned via pipes, L<system>,
551or backticks.
552
16d20bd9 553=item unlink LIST
554
555C<unlink> will delete the highest version of a file only; in
556order to delete all versions, you need to say
557 1 while (unlink LIST);
558You may need to make this change to scripts written for a
559Unix system which expect that after a call to C<unlink>,
560no files with the names passed to C<unlink> will exist.
4633a7c4 561(Note: This can be changed at compile time; if you
562C<use Config> and C<$Config{'d_unlink_all_versions'}> is
563C<define>, then C<unlink> will delete all versions of a
564file on the first call.)
16d20bd9 565
566C<unlink> will delete a file if at all possible, even if it
567requires changing file protection (though it won't try to
568change the protection of the parent directory). You can tell
569whether you've got explicit delete access to a file by using the
570C<VMS::Filespec::candelete> operator. For instance, in order
571to delete only files to which you have delete access, you could
572say something like
4e592037 573
16d20bd9 574 sub safe_unlink {
575 my($file,$num);
576 foreach $file (@_) {
577 next unless VMS::Filespec::candelete($file);
578 $num += unlink $file;
579 }
580 $num;
581 }
4e592037 582
583(or you could just use C<VMS::Stdio::remove>, if you've installed
584the VMS::Stdio extension distributed with Perl). If C<unlink> has to
585change the file protection to delete the file, and you interrupt it
586in midstream, the file may be left intact, but with a changed ACL
587allowing you delete access.
16d20bd9 588
748a9306 589=item utime LIST
590
591Since ODS-2, the VMS file structure for disk files, does not keep
592track of access times, this operator changes only the modification
593time of the file (VMS revision date).
594
595=item waitpid PID,FLAGS
596
597If PID is a subprocess started by a piped L<open>, C<waitpid>
598will wait for that subprocess, and return its final
599status value. If PID is a subprocess created in some other way
600(e.g. SPAWNed before Perl was invoked), or is not a subprocess of
601the current process, C<waitpid> will check once per second whether
602the process has completed, and when it has, will return 0. (If PID
603specifies a process that isn't a subprocess of the current process,
604and you invoked Perl with the C<-w> switch, a warning will be issued.)
605
606The FLAGS argument is ignored in all cases.
a0d0e21e 607
a5f75d66 608=head1 Perl variables
609
610=item %ENV
611
612Reading the elements of the %ENV array returns the
613translation of the logical name specified by the key,
614according to the normal search order of access modes and
615logical name tables. If you append a semicolon to the
616logical name, followed by an integer, that integer is
617used as the translation index for the logical name,
618so that you can look up successive values for search
619list logical names. For instance, if you say
620
621 $ Define STORY once,upon,a,time,there,was
622 $ perl -e "for ($i = 0; $i <= 6; $i++) " -
740ce14c 623 _$ -e "{ print $ENV{'story;'.$i},' '}"
a5f75d66 624
625Perl will print C<ONCE UPON A TIME THERE WAS>.
626
627The %ENV keys C<home>, C<path>,C<term>, and C<user>
628return the CRTL "environment variables" of the same
629names, if these logical names are not defined. The
630key C<default> returns the current default device
631and directory specification, regardless of whether
632there is a logical name DEFAULT defined..
633
634Setting an element of %ENV defines a supervisor-mode logical
635name in the process logical name table. C<Undef>ing or
636C<delete>ing an element of %ENV deletes the equivalent user-
637mode or supervisor-mode logical name from the process logical
638name table. If you use C<undef>, the %ENV element remains
639empty. If you use C<delete>, another attempt is made at
640logical name translation after the deletion, so an inner-mode
641logical name or a name in another logical name table will
642replace the logical name just deleted. It is not possible
643at present to define a search list logical name via %ENV.
644
740ce14c 645At present, the first time you iterate over %ENV using
edc7bc49 646C<keys>, or C<values>, you will incur a time penalty as all
647logical names are read, in order to fully populate %ENV.
648Subsequent iterations will not reread logical names, so they
649won't be as slow, but they also won't reflect any changes
650to logical name tables caused by other programs. The C<each>
651operator is special: it returns each element I<already> in
652%ENV, but doesn't go out and look for more. Therefore, if
653you've previously used C<keys> or C<values>, you'll see all
654the logical names visible to your process, and if not, you'll
655see only the names you've looked up so far. (This is a
656consequence of the way C<each> is implemented now, and it
657may change in the future, so it wouldn't be a good idea
658to rely on it too much.)
740ce14c 659
a5f75d66 660In all operations on %ENV, the key string is treated as if it
661were entirely uppercase, regardless of the case actually
662specified in the Perl expression.
663
664=item $?
665
666Since VMS status values are 32 bits wide, the value of C<$?>
667is simply the final status value of the last subprocess to
668complete. This differs from the behavior of C<$?> under Unix,
669and under VMS' POSIX environment, in that the low-order 8 bits
670of C<$?> do not specify whether the process terminated normally
671or due to a signal, and you do not need to shift C<$?> 8 bits
672to the right in order to find the process' exit status.
673
674=item $!
675
676The string value of C<$!> is that returned by the CRTL's
677strerror() function, so it will include the VMS message for
678VMS-specific errors. The numeric value of C<$!> is the
679value of C<errno>, except if errno is EVMSERR, in which
680case C<$!> contains the value of vaxc$errno. Setting C<$!>
4e592037 681always sets errno to the value specified. If this value is
682EVMSERR, it also sets vaxc$errno to 4 (NONAME-F-NOMSG), so
683that the string value of C<$!> won't reflect the VMS error
684message from before C<$!> was set.
685
686=item $^E
687
688This variable provides direct access to VMS status values
689in vaxc$errno, which are often more specific than the
690generic Unix-style error messages in C<$!>. Its numeric value
691is the value of vaxc$errno, and its string value is the
692corresponding VMS message string, as retrieved by sys$getmsg().
693Setting C<$^E> sets vaxc$errno to the value specified.
694
695=item $|
696
697Setting C<$|> for an I/O stream causes data to be flushed
698all the way to disk on each write (I<i.e.> not just to
699the underlying RMS buffers for a file). In other words,
700it's equivalent to calling fflush() and fsync() from C.
a5f75d66 701
748a9306 702=head1 Revision date
a0d0e21e 703
4e592037 704This document was last updated on 28-Feb-1996, for Perl 5,
e518068a 705patchlevel 2.
706
707=head1 AUTHOR
708
709Charles Bailey bailey@genetics.upenn.edu
710