1 ''' Beginning of part 2
2 ''' $Header: perl.man.2,v 1.0.1.3 88/02/01 17:33:03 root Exp $
4 ''' $Log: perl.man.2,v $
5 ''' Revision 1.0.1.3 88/02/01 17:33:03 root
6 ''' patch12: documented split more adequately.
8 ''' Revision 1.0.1.2 88/01/30 17:04:28 root
9 ''' patch 11: random cleanup
11 ''' Revision 1.0.1.1 88/01/28 10:25:11 root
12 ''' patch8: added $@ variable.
14 ''' Revision 1.0 87/12/18 16:18:41 root
19 Finds the statement labeled with LABEL and resumes execution there.
20 Currently you may only go to statements in the main body of the program
21 that are not nested inside a do {} construct.
22 This statement is not implemented very efficiently, and is here only to make
23 the sed-to-perl translator easier.
26 Returns the decimal value of EXPR interpreted as an hex string.
27 (To interpret strings that might start with 0 or 0x see oct().)
28 .Ip "index(STR,SUBSTR)" 8 4
29 Returns the position of SUBSTR in STR, based at 0, or whatever you've
30 set the $[ variable to.
31 If the substring is not found, returns one less than the base, ordinarily -1.
33 Returns the integer portion of EXPR.
34 .Ip "join(EXPR,LIST)" 8 8
35 .Ip "join(EXPR,ARRAY)" 8
36 Joins the separate strings of LIST or ARRAY into a single string with fields
37 separated by the value of EXPR, and returns the string.
41 $_ = join(\|':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
46 .Ip "keys(ASSOC_ARRAY)" 8 6
47 Returns a normal array consisting of all the keys of the named associative
49 The keys are returned in an apparently random order, but it is the same order
50 as either the values() or each() function produces (given that the associative array
51 has not been modified).
52 Here is yet another way to print your environment:
57 @values = values(ENV);
59 print pop(keys),'=',pop(values),"\n";
64 Sends a signal to a list of processes.
65 The first element of the list must be the (numerical) signal to send.
66 LIST may be an array, in which case you may wish to use the unshift
67 command to put the signal on the front of the array.
68 Returns the number of processes successfully signaled.
69 Note: in order to use the value you must put the whole thing in parentheses:
72 $cnt = (kill 9,$child1,$child2);
81 statement in C (as used in loops); it immediately exits the loop in question.
82 If the LABEL is omitted, the command refers to the innermost enclosing loop.
85 block, if any, is not executed:
89 line: while (<stdin>) {
90 last line if /\|^$/; # exit when done with header
95 .Ip "localtime(EXPR)" 8 4
96 Converts a time as returned by the time function to a 9-element array with
97 the time analyzed for the local timezone.
98 Typically used as follows:
102 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
106 All array elements are numeric.
108 Returns logarithm (base e) of EXPR.
115 statement in C; it starts the next iteration of the loop:
119 line: while (<stdin>) {
120 next line if /\|^#/; # discard comments
125 Note that if there were a
127 block on the above, it would get executed even on discarded lines.
128 If the LABEL is omitted, the command refers to the innermost enclosing loop.
129 .Ip "length(EXPR)" 8 2
130 Returns the length in characters of the value of EXPR.
131 .Ip "link(OLDFILE,NEWFILE)" 8 2
132 Creates a new filename linked to the old filename.
133 Returns 1 for success, 0 otherwise.
135 Returns the decimal value of EXPR interpreted as an octal string.
136 (If EXPR happens to start off with 0x, interprets it as a hex string instead.)
137 The following will handle decimal, octal and hex in the standard notation:
140 $val = oct($val) if $val =~ /^0/;
143 .Ip "open(FILEHANDLE,EXPR)" 8 8
144 .Ip "open(FILEHANDLE)" 8
145 .Ip "open FILEHANDLE" 8
146 Opens the file whose filename is given by EXPR, and associates it with
148 If EXPR is omitted, the string variable of the same name as the FILEHANDLE
149 contains the filename.
150 If the filename begins with \*(L">\*(R", the file is opened for output.
151 If the filename begins with \*(L">>\*(R", the file is opened for appending.
152 If the filename begins with \*(L"|\*(R", the filename is interpreted
153 as a command to which output is to be piped, and if the filename ends
154 with a \*(L"|\*(R", the filename is interpreted as command which pipes
156 (You may not have a command that pipes both in and out.)
157 Opening '\-' opens stdin and opening '>\-' opens stdout.
158 Open returns 1 upon success, '' otherwise.
164 open article || die "Can't find article $article";
165 while (<article>) {\|.\|.\|.
167 open(log, '>>/usr/spool/news/twitlog'\|);
169 open(article, "caeser <$article |"\|); # decrypt article
171 open(extract, "|sort >/tmp/Tmp$$"\|); # $$ is our process#
175 Returns the ascii value of the first character of EXPR.
178 Pops and returns the last value of the array, shortening the array by 1.
179 ''' $tmp = $ARRAY[$#ARRAY--]
180 .Ip "print FILEHANDLE LIST" 8 9
183 Prints a string or comma-separated list of strings.
184 If FILEHANDLE is omitted, prints by default to standard output (or to the
185 last selected output channel\*(--see select()).
186 If LIST is also omitted, prints $_ to stdout.
187 LIST may also be an array value.
188 To set the default output channel to something other than stdout use the select operation.
189 .Ip "printf FILEHANDLE LIST" 8 9
191 Equivalent to a "print FILEHANDLE sprintf(LIST)".
192 .Ip "push(ARRAY,EXPR)" 8 7
193 Treats ARRAY (@ is optional) as a stack, and pushes the value of EXPR
194 onto the end of ARRAY.
195 The length of ARRAY increases by 1.
196 Has the same effect as
199 $ARRAY[$#ARRAY+1] = EXPR;
202 but is more efficient.
207 command restarts the loop block without evaluating the conditional again.
210 block, if any, is not executed.
211 If the LABEL is omitted, the command refers to the innermost enclosing loop.
212 This command is normally used by programs that want to lie to themselves
213 about what was just input:
217 # a simpleminded Pascal comment stripper
218 # (warning: assumes no { or } in strings)
219 line: while (<stdin>) {
220 while (s|\|({.*}.*\|){.*}|$1 \||) {}
225 if (\|/\|}/\|) { # end of comment?
235 .Ip "rename(OLDNAME,NEWNAME)" 8 2
236 Changes the name of a file.
237 Returns 1 for success, 0 otherwise.
241 block at the end of a loop to clear variables and reset ?? searches
242 so that they work again.
243 The expression is interpreted as a list of single characters (hyphens allowed
245 All string variables beginning with one of those letters are set to the null
247 If the expression is omitted, one-match searches (?pattern?) are reset to
254 reset 'X'; \h'|2i'# reset all X variables
255 reset 'a-z';\h'|2i'# reset lower case variables
256 reset; \h'|2i'# just reset ?? searches
259 .Ip "s/PATTERN/REPLACEMENT/g" 8 3
260 Searches a string for a pattern, and if found, replaces that pattern with the
261 replacement text and returns the number of substitutions made.
262 Otherwise it returns false (0).
263 The \*(L"g\*(R" is optional, and if present, indicates that all occurences
264 of the pattern are to be replaced.
265 Any delimiter may replace the slashes; if single quotes are used, no
266 interpretation is done on the replacement string.
267 If no string is specified via the =~ or !~ operator,
268 the $_ string is searched and modified.
269 (The string specified with =~ must be a string variable or array element,
271 If the pattern contains a $ that looks like a variable rather than an
272 end-of-string test, the variable will be interpolated into the pattern at
274 See also the section on regular expressions.
278 s/\|\e\|bgreen\e\|b/mauve/g; # don't change wintergreen
280 $path \|=~ \|s|\|/usr/bin|\|/usr/local/bin|;
282 s/Login: $foo/Login: $bar/; # run-time pattern
284 s/\|([^ \|]*\|) *\|([^ \|]*\|)\|/\|$2 $1/; # reverse 1st two fields
287 (Note the use of $ instead of \|\e\| in the last example. See section
288 on regular expressions.)
289 .Ip "seek(FILEHANDLE,POSITION,WHENCE)" 8 3
290 Randomly positions the file pointer for FILEHANDLE, just like the fseek()
292 Returns 1 upon success, 0 otherwise.
293 .Ip "select(FILEHANDLE)" 8 3
294 Sets the current default filehandle for output.
295 This has two effects: first, a
299 without a filehandle will default to this FILEHANDLE.
300 Second, references to variables related to output will refer to this output
302 For example, if you have to set the top of form format for more than
303 one output channel, you might do the following:
313 Select happens to return TRUE if the file is currently open and FALSE otherwise,
314 but this has no effect on its operation.
315 .Ip "shift(ARRAY)" 8 6
318 Shifts the first value of the array off, shortening the array by 1 and
319 moving everything down.
320 If ARRAY is omitted, shifts the ARGV array.
321 See also unshift(), push() and pop().
322 Shift() and unshift() do the same thing to the left end of an array that push()
323 and pop() do to the right end.
326 Causes the script to sleep for EXPR seconds, or forever if no EXPR.
327 May be interrupted by sending the process a SIGALARM.
328 Returns the number of seconds actually slept.
329 .Ip "split(/PATTERN/,EXPR)" 8 8
330 .Ip "split(/PATTERN/)" 8
332 Splits a string into an array of strings, and returns it.
333 If EXPR is omitted, splits the $_ string.
334 If PATTERN is also omitted, splits on whitespace (/[\ \et\en]+/).
335 Anything matching PATTERN is taken to be a delimiter separating the fields.
336 (Note that the delimiter may be longer than one character.)
337 Trailing null fields are stripped, which potential users of pop() would
339 A pattern matching the null string (not to be confused with a null pattern)
340 will split the value of EXPR into separate characters at each point it
345 print join(':',split(/ */,'hi there'));
348 produces the output 'h:i:t:h:e:r:e'.
350 The pattern /PATTERN/ may be replaced with an expression to specify patterns
351 that vary at runtime.
352 As a special case, specifying a space ('\ ') will split on white space
353 just as split with no arguments does, but leading white space does NOT
354 produce a null first field.
355 Thus, split('\ ') can be used to emulate awk's default behavior, whereas
356 split(/\ /) will give you as many null initial fields as there are
363 open(passwd, '/etc/passwd');
366 ($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(\|/\|:\|/\|);
369 ($login, $passwd, $uid, $gid, $gcos, $home, $shell)
370 = split(\|/\|:\|/\|);
376 (Note that $shell above will still have a newline on it. See chop().)
379 .Ip "sprintf(FORMAT,LIST)" 8 4
380 Returns a string formatted by the usual printf conventions.
381 The * character is not supported.
383 Return the square root of EXPR.
384 .Ip "stat(FILEHANDLE)" 8 6
386 Returns a 13-element array giving the statistics for a file, either the file
387 opened via FILEHANDLE, or named by EXPR.
388 Typically used as follows:
392 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
393 $atime,$mtime,$ctime,$blksize,$blocks)
397 .Ip "substr(EXPR,OFFSET,LEN)" 8 2
398 Extracts a substring out of EXPR and returns it.
399 First character is at offset 0, or whatever you've set $[ to.
400 .Ip "system LIST" 8 6
401 Does exactly the same thing as \*(L"exec LIST\*(R" except that a fork
402 is done first, and the parent process waits for the child process to complete.
403 Note that argument processing varies depending on the number of arguments.
404 The return value is the exit status of the program.
406 .Ip "tell(FILEHANDLE)" 8 6
408 Returns the current file position for FILEHANDLE.
409 If FILEHANDLE is omitted, assumes the file last read.
411 Returns the number of seconds since January 1, 1970.
412 Suitable for feeding to gmtime() and localtime().
414 Returns a four-element array giving the user and system times, in seconds, for this
415 process and the children of this process.
417 ($user,$system,$cuser,$csystem) = times;
419 .Ip "tr/SEARCHLIST/REPLACEMENTLIST/" 8 5
420 .Ip "y/SEARCHLIST/REPLACEMENTLIST/" 8
421 Translates all occurences of the characters found in the search list with
422 the corresponding character in the replacement list.
423 It returns the number of characters replaced.
424 If no string is specified via the =~ or !~ operator,
425 the $_ string is translated.
426 (The string specified with =~ must be a string variable or array element,
432 is provided as a synonym for
437 $ARGV[1] \|=~ \|y/A-Z/a-z/; \h'|3i'# canonicalize to lower case
439 $cnt = tr/*/*/; \h'|3i'# count the stars in $_
442 .Ip "umask(EXPR)" 8 3
443 Sets the umask for the process and returns the old one.
444 .Ip "unlink LIST" 8 2
445 Deletes a list of files.
446 LIST may be an array.
447 Returns the number of files successfully deleted.
448 Note: in order to use the value you must put the whole thing in parentheses:
451 $cnt = (unlink 'a','b','c');
455 .Ip "unshift(ARRAY,LIST)" 8 4
456 Does the opposite of a shift.
457 Prepends list to the front of the array, and returns the number of elements
461 unshift(ARGV,'-e') unless $ARGV[0] =~ /^-/;
464 .Ip "values(ASSOC_ARRAY)" 8 6
465 Returns a normal array consisting of all the values of the named associative
467 The values are returned in an apparently random order, but it is the same order
468 as either the keys() or each() function produces (given that the associative array
469 has not been modified).
470 See also keys() and each().
471 .Ip "write(FILEHANDLE)" 8 6
474 Writes a formatted record (possibly multi-line) to the specified file,
475 using the format associated with that file.
476 By default the format for a file is the one having the same name is the
477 filehandle, but the format for the current output channel (see
479 may be set explicitly
480 by assigning the name of the format to the $~ variable.
482 Top of form processing is handled automatically:
483 if there is insufficient room on the current page for the formatted
484 record, the page is advanced, a special top-of-page format is used
485 to format the new page header, and then the record is written.
486 By default the top-of-page format is \*(L"top\*(R", but it
488 format of your choice by assigning the name to the $^ variable.
490 If FILEHANDLE is unspecified, output goes to the current default output channel,
491 which starts out as stdout but may be changed by the
494 If the FILEHANDLE is an EXPR, then the expression is evaluated and the
495 resulting string is used to look up the name of the FILEHANDLE at run time.
496 For more on formats, see the section on formats later on.
498 A subroutine may be declared as follows:
505 Any arguments passed to the routine come in as array @_,
506 that is ($_[0], $_[1], .\|.\|.).
507 The return value of the subroutine is the value of the last expression
509 There are no local variables\*(--everything is a global variable.
511 A subroutine is called using the
514 (CAVEAT: For efficiency reasons recursive subroutine calls are not currently
516 This restriction may go away in the future. Then again, it may not.)
524 while ($foo = pop(@_)) {
525 $max = $foo \|if \|$max < $foo;
531 $bestday = do MAX($mon,$tue,$wed,$thu,$fri);
536 # get a line, combining continuation lines
537 # that start with whitespace
539 $thisline = $lookahead;
540 line: while ($lookahead = <stdin>) {
541 if ($lookahead \|=~ \|/\|^[ \^\e\|t]\|/\|) {
542 $thisline \|.= \|$lookahead;
551 $lookahead = <stdin>; # get first line
552 while ($_ = get_line(\|)) {
559 Use array assignment to name your formal arguments:
563 $foo{$key} = $value unless $foo{$key};
567 .Sh "Regular Expressions"
568 The patterns used in pattern matching are regular expressions such as
571 In addition, \ew matches an alphanumeric character and \eW a nonalphanumeric.
572 Word boundaries may be matched by \eb, and non-boundaries by \eB.
573 The bracketing construct \|(\ .\|.\|.\ \|) may also be used, $<digit>
574 matches the digit'th substring, where digit can range from 1 to 9.
575 (You can also use the old standby \e<digit> in search patterns,
576 but $<digit> also works in replacement patterns and in the block controlled
577 by the current conditional.)
578 $+ returns whatever the last bracket match matched.
579 $& returns the entire matched string.
580 Up to 10 alternatives may given in a pattern, separated by |, with the
581 caveat that \|(\ .\|.\|.\ |\ .\|.\|.\ \|) is illegal.
585 s/\|^\|([^ \|]*\|) \|*([^ \|]*\|)\|/\|$2 $1\|/; # swap first two words
588 if (/\|Time: \|(.\|.\|):\|(.\|.\|):\|(.\|.\|)\|/\|) {
595 By default, the ^ character matches only the beginning of the string, and
597 does certain optimizations with the assumption that the string contains
599 You may, however, wish to treat a string as a multi-line buffer, such that
600 the ^ will match after any newline within the string.
601 At the cost of a little more overhead, you can do this by setting the variable
603 Setting it back to 0 makes
605 revert to its old behavior.
607 Output record formats for use with the
609 operator may declared as follows:
618 If name is omitted, format \*(L"stdout\*(R" is defined.
619 FORMLIST consists of a sequence of lines, each of which may be of one of three
624 A \*(L"picture\*(R" line giving the format for one output line.
626 An argument line supplying values to plug into a picture line.
628 Picture lines are printed exactly as they look, except for certain fields
629 that substitute values into the line.
630 Each picture field starts with either @ or ^.
631 The @ field (not to be confused with the array marker @) is the normal
632 case; ^ fields are used
633 to do rudimentary multi-line text block filling.
634 The length of the field is supplied by padding out the field
635 with multiple <, >, or | characters to specify, respectively, left justfication,
636 right justification, or centering.
637 If any of the values supplied for these fields contains a newline, only
638 the text up to the newline is printed.
639 The special field @* can be used for printing multi-line values.
640 It should appear by itself on a line.
642 The values are specified on the following line, in the same order as
644 They must currently be either string variable names or string literals (or
646 Currently you can separate values with spaces, but commas may be placed
647 between values to prepare for possible future versions in which full expressions
648 are allowed as values.
650 Picture fields that begin with ^ rather than @ are treated specially.
651 The value supplied must be a string variable name which contains a text
654 puts as much text as it can into the field, and then chops off the front
655 of the string so that the next time the string variable is referenced,
656 more of the text can be printed.
657 Normally you would use a sequence of fields in a vertical stack to print
659 If you like, you can end the final field with .\|.\|., which will appear in the
660 output if the text was too long to appear in its entirety.
662 Since use of ^ fields can produce variable length records if the text to be
663 formatted is short, you can suppress blank lines by putting the tilde (~)
664 character anywhere in the line.
665 (Normally you should put it in the front if possible.)
666 The tilde will be translated to a space upon output.
674 # a report on the /etc/passwd file
677 Name Login Office Uid Gid Home
678 ------------------------------------------------------------------
681 @<<<<<<<<<<<<<<<<<< @||||||| @<<<<<<@>>>> @>>>> @<<<<<<<<<<<<<<<<<
682 $name $login $office $uid $gid $home
686 # a report from a bug report form
689 @<<<<<<<<<<<<<<<<<<<<<<< @||| @>>>>>>>>>>>>>>>>>>>>>>>
691 ------------------------------------------------------------------
694 Subject: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
696 Index: @<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
697 \& $index $description
698 Priority: @<<<<<<<<<< Date: @<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
699 \& $priority $date $description
700 From: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
701 \& $from $description
702 Assigned to: @<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
703 \& $programmer $description
704 \&~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
706 \&~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
708 \&~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
710 \&~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<
712 \&~ ^<<<<<<<<<<<<<<<<<<<<<<<...
718 It is possible to intermix prints with writes on the same output channel,
719 but you'll have to handle $\- (lines left on the page) yourself.
722 If you are printing lots of fields that are usually blank, you should consider
723 using the reset operator between records.
724 Not only is it more efficient, but it can prevent the bug of adding another
725 field and forgetting to zero it.
726 .Sh "Predefined Names"
727 The following names have special meaning to
729 I could have used alphabetic symbols for some of these, but I didn't want
730 to take the chance that someone would say reset "a-zA-Z" and wipe them all
732 You'll just have to suffer along with these silly symbols.
733 Most of them have reasonable mnemonics, or analogues in one of the shells.
735 The default input and pattern-searching space.
736 The following pairs are equivalent:
740 while (<>) {\|.\|.\|. # only equivalent in while!
741 while ($_ = <>) {\|.\|.\|.
745 $_ \|=~ \|/\|^Subject:/
756 (Mnemonic: underline is understood in certain operations.)
758 The current input line number of the last file that was read.
760 (Mnemonic: many programs use . to mean the current line number.)
762 The input record separator, newline by default.
763 Works like awk's RS variable, including treating blank lines as delimiters
764 if set to the null string.
765 If set to a value longer than one character, only the first character is used.
766 (Mnemonic: / is used to delimit line boundaries when quoting poetry.)
768 The output field separator for the print operator.
769 Ordinarily the print operator simply prints out the comma separated fields
771 In order to get behavior more like awk, set this variable as you would set
772 awk's OFS variable to specify what is printed between fields.
773 (Mnemonic: what is printed when there is a , in your print statement.)
775 The output record separator for the print operator.
776 Ordinarily the print operator simply prints out the comma separated fields
777 you specify, with no trailing newline or record separator assumed.
778 In order to get behavior more like awk, set this variable as you would set
779 awk's ORS variable to specify what is printed at the end of the print.
780 (Mnemonic: you set $\e instead of adding \en at the end of the print.
781 Also, it's just like /, but it's what you get \*(L"back\*(R" from perl.)
783 The output format for printed numbers.
784 This variable is a half-hearted attempt to emulate awk's OFMT variable.
785 There are times, however, when awk and perl have differing notions of what
787 Also, the initial value is %.20g rather than %.6g, so you need to set $#
788 explicitly to get awk's value.
789 (Mnemonic: # is the number sign.)
791 The current page number of the currently selected output channel.
792 (Mnemonic: % is page number in nroff.)
794 The current page length (printable lines) of the currently selected output
797 (Mnemonic: = has horizontal lines.)
799 The number of lines left on the page of the currently selected output channel.
800 (Mnemonic: lines_on_page - lines_printed.)
802 The name of the current report format for the currently selected output
804 (Mnemonic: brother to $^.)
806 The name of the current top-of-page format for the currently selected output
808 (Mnemonic: points to top of page.)
810 If set to nonzero, forces a flush after every write or print on the currently
811 selected output channel.
813 Note that stdout will typically be line buffered if output is to the
814 terminal and block buffered otherwise.
815 Setting this variable is useful primarily when you are outputting to a pipe,
816 such as when you are running a perl script under rsh and want to see the
817 output as it's happening.
818 (Mnemonic: when you want your pipes to be piping hot.)
820 The process number of the
823 (Mnemonic: same as shells.)
825 The status returned by the last backtick (``) command.
826 (Mnemonic: same as sh and ksh.)
828 The last bracket matched by the last search pattern.
829 This is useful if you don't know which of a set of alternative patterns
834 /Version: \|(.*\|)|Revision: \|(.*\|)\|/ \|&& \|($rev = $+);
837 (Mnemonic: be positive and forward looking.)
839 Set to 1 to do multiline matching within a string, 0 to assume strings contain
842 (Mnemonic: * matches multiple things.)
844 Contains the name of the file containing the
846 script being executed.
847 The value should be copied elsewhere before any pattern matching happens, which
849 (Mnemonic: same as sh and ksh.)
851 Contains the subpattern from the corresponding set of parentheses in the last
852 pattern matched, not counting patterns matched in nested blocks that have
854 (Mnemonic: like \edigit.)
856 The index of the first element in an array, and of the first character in
858 Default is 0, but you could set it to 1 to make
863 when subscripting and when evaluating the index() and substr() functions.
864 (Mnemonic: [ begins subscripts.)
866 The current value of errno, with all the usual caveats.
867 (Mnemonic: What just went bang?)
869 The error message from the last eval command.
870 If null, the last eval parsed and executed correctly.
871 (Mnemonic: Where was the syntax error "at"?)
873 The array ARGV contains the command line arguments intended for the script.
874 Note that $#ARGV is the generally number of arguments minus one, since
875 $ARGV[0] is the first argument, NOT the command name.
876 See $0 for the command name.
878 The associative array ENV contains your current environment.
879 Setting a value in ENV changes the environment for child processes.
881 The associative array SIG is used to set signal handlers for various signals.
886 sub handler { # 1st argument is signal name
888 print "Caught a SIG$sig--shutting down\n";
893 $SIG{'INT'} = 'handler';
894 $SIG{'QUIT'} = 'handler';
896 $SIG{'INT'} = 'DEFAULT'; # restore default action
897 $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT
902 currently uses no environment variables, except to make them available
903 to the script being executed, and to child processes.
904 However, scripts running setuid would do well to execute the following lines
905 before doing anything else, just to keep people honest:
909 $ENV{'PATH'} = '/bin:/usr/bin'; # or whatever you need
910 $ENV{'SHELL'} = '/bin/sh' if $ENV{'SHELL'};
911 $ENV{'IFS'} = '' if $ENV{'IFS'};
915 Larry Wall <lwall@jpl-devvax.Jpl.Nasa.Gov>
917 /tmp/perl\-eXXXXXX temporary file for
921 a2p awk to perl translator
923 s2p sed to perl translator
925 perldb interactive perl debugger
927 Compilation errors will tell you the line number of the error, with an
928 indication of the next token or token type that was to be examined.
929 (In the case of a script passed to
935 is counted as one line.)
937 Accustomed awk users should take special note of the following:
939 Semicolons are required after all simple statements in perl. Newline
940 is not a statement delimiter.
942 Curly brackets are required on ifs and whiles.
944 Variables begin with $ or @ in perl.
946 Arrays index from 0 unless you set $[.
947 Likewise string positions in substr() and index().
949 You have to decide whether your array has numeric or string indices.
951 You have to decide whether you want to use string or numeric comparisons.
953 Reading an input line does not split it for you. You get to split it yourself
955 And split has different arguments.
957 The current input line is normally in $_, not $0.
958 It generally does not have the newline stripped.
959 ($0 is initially the name of the program executed, then the last matched
962 The current filename is $ARGV, not $FILENAME.
963 NR, RS, ORS, OFS, and OFMT have equivalents with other symbols.
964 FS doesn't have an equivalent, since you have to be explicit about
967 $<digit> does not refer to fields--it refers to substrings matched by the last
970 The print statement does not add field and record separators unless you set
973 You must open your files before you print to them.
975 The range operator is \*(L"..\*(R", not comma.
976 (The comma operator works as in C.)
978 The match operator is \*(L"=~\*(R", not \*(L"~\*(R".
979 (\*(L"~\*(R" is the one's complement operator.)
981 The concatenation operator is \*(L".\*(R", not the null string.
982 (Using the null string would render \*(L"/pat/ /pat/\*(R" unparseable,
983 since the third slash would be interpreted as a division operator\*(--the
984 tokener is in fact slightly context sensitive for operators like /, ?, and <.
985 And in fact, . itself can be the beginning of a number.)
987 The \ennn construct in patterns must be given as [\ennn] to avoid interpretation
990 Next, exit, and continue work differently.
992 When in doubt, run the awk construct through a2p and see what it gives you.
994 Cerebral C programmers should take note of the following:
996 Curly brackets are required on ifs and whiles.
998 You should use \*(L"elsif\*(R" rather than \*(L"else if\*(R"
1000 Break and continue become last and next, respectively.
1002 There's no switch statement.
1004 Variables begin with $ or @ in perl.
1006 Printf does not implement *.
1008 Comments begin with #, not /*.
1010 You can't take the address of anything.
1012 Subroutines are not reentrant.
1014 ARGV must be capitalized.
1016 The \*(L"system\*(R" calls link, unlink, rename, etc. return 1 for success, not 0.
1018 Signal handlers deal with signal names, not numbers.
1020 Seasoned sed programmers should take note of the following:
1022 Backreferences in substitutions use $ rather than \e.
1024 The pattern matching metacharacters (, ), and | do not have backslashes in front.
1027 You can't currently dereference array elements inside a double-quoted string.
1028 You must assign them to a temporary and interpolate that.
1030 Associative arrays really ought to be first class objects.
1032 Recursive subroutines are not currently supported, due to the way temporary
1033 values are stored in the syntax tree.
1035 Arrays ought to be passable to subroutines just as strings are.
1037 The array literal consisting of one element is currently misinterpreted, i.e.
1046 actually stands for Pathologically Eclectic Rubbish Lister, but don't tell