home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / perl / !Perl / Manual / perlvar < prev   
Encoding:
Text File  |  1995-04-18  |  24.3 KB  |  721 lines

  1. <!-- $RCSfile$$Revision$$Date$ -->
  2. <!-- $Log$ -->
  3. <HTML>
  4. <TITLE> PERLVAR </TITLE>
  5. <h2>NAME</h2>
  6. perlvar - Perl predefined variables
  7. <p><h2>DESCRIPTION</h2>
  8. <h3>Predefined Names</h3>
  9. The following names have special meaning to Perl.  Most of the
  10. punctuational names have reasonable mnemonics, or analogues in one of
  11. the shells.  Nevertheless, if you wish to use the long variable names,
  12. you just need to say
  13. <p><pre>
  14.         use English;
  15. </pre>
  16. at the top of your program.  This will alias all the short names to the
  17. long names in the current package.  Some of them even have medium names,
  18. generally borrowed from <B>awk</B>.
  19. <p>To go a step further, those variables that depend on the currently
  20. selected filehandle may instead be set by calling an object method on
  21. the FileHandle object.  (Summary lines below for this contain the word
  22. HANDLE.)  First you must say
  23. <p><pre>
  24.         use FileHandle;
  25. </pre>
  26. after which you may use either
  27. <p><pre>
  28.         method HANDLE EXPR
  29. </pre>
  30. or
  31. <p><pre>
  32.         HANDLE->method(EXPR)
  33. </pre>
  34. Each of the methods returns the old value of the FileHandle attribute.
  35. The methods each take an optional EXPR, which if supplied specifies the
  36. new value for the FileHandle attribute in question.  If not supplied,
  37. most of the methods do nothing to the current value, except for
  38. autoflush(), which will assume a 1 for you, just to be different.
  39. <p>A few of these variables are considered "read-only".  This means that if you 
  40. try to assign to this variable, either directly or indirectly through
  41. a reference.  If you attempt to do so, you'll raise a run-time exception.
  42. <p>
  43. <dl>
  44.  
  45. <dt><b><A NAME="perlvar_370">$ARG</A></b>
  46.  
  47. <dt><b><A NAME="perlvar_371">$_</A></b>
  48. <dd>
  49. The default input and pattern-searching space.  The following pairs are
  50. equivalent:
  51. <p></dd>
  52. <pre>
  53.         while (<>) {...}  # only equivalent in while!
  54.         while ($_ = <>) {...}
  55. </pre>
  56. <pre>
  57.         /^Subject:/
  58.         $_ =~ /^Subject:/
  59. </pre>
  60. <pre>
  61.         tr/a-z/A-Z/
  62.         $_ =~ tr/a-z/A-Z/
  63. </pre>
  64. <pre>
  65.         chop
  66.         chop($_)
  67. </pre>
  68. (Mnemonic: underline is understood in certain operations.)
  69. <p><dt><B>$<<I>digit</I>></B>
  70. <dd>
  71. Contains the subpattern from the corresponding set of parentheses in
  72. the last pattern matched, not counting patterns matched in nested
  73. blocks that have been exited already.  (Mnemonic: like \digit.)
  74. These variables are all read-only.
  75. <p></dd>
  76.  
  77. <dt><b><A NAME="perlvar_373">$MATCH</A></b>
  78. <dt><B>$&</B>
  79. <dd>
  80. The string matched by the last successful pattern match (not counting
  81. any matches hidden within a BLOCK or eval() enclosed by the current
  82. BLOCK).  (Mnemonic: like & in some editors.)  This variable is read-only.
  83. <p></dd>
  84.  
  85. <dt><b><A NAME="perlvar_375">$PREMATCH</A></b>
  86.  
  87. <dt><b><A NAME="perlvar_376">$`</A></b>
  88. <dd>
  89. The string preceding whatever was matched by the last successful
  90. pattern match (not counting any matches hidden within a BLOCK or eval
  91. enclosed by the current BLOCK).  (Mnemonic: ` often precedes a quoted
  92. string.)  This variable is read-only.
  93. <p></dd>
  94.  
  95. <dt><b><A NAME="perlvar_377">$POSTMATCH</A></b>
  96.  
  97. <dt><b><A NAME="perlvar_378">$'</A></b>
  98. <dd>
  99. The string following whatever was matched by the last successful
  100. pattern match (not counting any matches hidden within a BLOCK or eval()
  101. enclosed by the current BLOCK).  (Mnemonic: ' often follows a quoted
  102. string.)  Example:
  103. <p></dd>
  104. <pre>
  105.         $_ = 'abcdefghi';
  106.         /def/;
  107.         print "$`:$&:$'\n";         # prints abc:def:ghi
  108. </pre>
  109. This variable is read-only.
  110. <p>
  111. <dt><b><A NAME="perlvar_379">$LAST_PAREN_MATCH</A></b>
  112.  
  113. <dt><b><A NAME="perlvar_380">$+</A></b>
  114. <dd>
  115. The last bracket matched by the last search pattern.  This is useful if
  116. you don't know which of a set of alternative patterns matched.  For
  117. example:
  118. <p></dd>
  119. <pre>
  120.         /Version: (.*)|Revision: (.*)/ && ($rev = $+);
  121. </pre>
  122. (Mnemonic: be positive and forward looking.)
  123. This variable is read-only.
  124. <p>
  125. <dt><b><A NAME="perlvar_381">$MULTILINE_MATCHING</A></b>
  126.  
  127. <dt><b><A NAME="perlvar_382">$*</A></b>
  128. <dd>
  129. Set to 1 to do multiline matching within a string, 0 to tell Perl
  130. that it can assume that strings contain a single line, for the purpose
  131. of optimizing pattern matches.  Pattern matches on strings containing
  132. multiple newlines can produce confusing results when "
  133. <A HREF="perlvar.html#perlvar_382">$*</A>
  134. " is 0.  Default
  135. is 0.  (Mnemonic: * matches multiple things.)  Note that this variable
  136. only influences the interpretation of "<B>^</B>" and "<B>$</B>".  A literal newline can
  137. be searched for even when <B>$* == 0</B>.
  138. <p></dd>
  139. Use of "
  140. <A HREF="perlvar.html#perlvar_382">$*</A>
  141. " is deprecated in Perl 5.
  142. <p>
  143. <dt><b><A NAME="perlvar_383">input_line_number HANDLE EXPR</A></b>
  144.  
  145. <dt><b><A NAME="perlvar_384">$INPUT_LINE_NUMBER</A></b>
  146.  
  147. <dt><b><A NAME="perlvar_385">$NR</A></b>
  148.  
  149. <dt><b><A NAME="perlvar_386">$.</A></b>
  150. <dd>
  151. The current input line number of the last filehandle that was read.
  152. This variable should be considered read-only.  
  153. Remember that only an explicit close on the filehandle
  154. resets the line number.  Since "<B><></B>" never does an explicit close, line
  155. numbers increase across ARGV files (but see examples under eof()).
  156. (Mnemonic: many programs use "." to mean the current line number.)
  157. <p></dd>
  158.  
  159. <dt><b><A NAME="perlvar_387">input_record_separator HANDLE EXPR</A></b>
  160.  
  161. <dt><b><A NAME="perlvar_388">$INPUT_RECORD_SEPARATOR</A></b>
  162.  
  163. <dt><b><A NAME="perlvar_389">$RS</A></b>
  164.  
  165. <dt><b><A NAME="perlvar_390">$/</A></b>
  166. <dd>
  167. The input record separator, newline by default.  Works like <B>awk</B>'s RS
  168. variable, including treating blank lines as delimiters if set to the
  169. null string.  You may set it to a multicharacter string to match a
  170. multi-character delimiter.  Note that setting it to <B>"\n\n"</B> means
  171. something slightly different than setting it to <B>""</B>, if the file
  172. contains consecutive blank lines.  Setting it to <B>""</B> will treat two or
  173. more consecutive blank lines as a single blank line.  Setting it to
  174. <B>"\n\n"</B> will blindly assume that the next input character belongs to the
  175. next paragraph, even if it's a newline.  (Mnemonic: / is used to
  176. delimit line boundaries when quoting poetry.)
  177. <p></dd>
  178. <pre>
  179.         undef $/;
  180.         $_ = <FH>;                # whole file now here
  181.         s/\n[ \t]+/ /g;
  182. </pre>
  183.  
  184. <dt><b><A NAME="perlvar_391">autoflush HANDLE EXPR</A></b>
  185.  
  186. <dt><b><A NAME="perlvar_392">$OUTPUT_AUTOFLUSH</A></b>
  187.  
  188. <dt><b><A NAME="perlvar_393">$|</A></b>
  189. <dd>
  190. If set to nonzero, forces a flush after every write or print on the
  191. currently selected output channel.  Default is 0.  Note that STDOUT
  192. will typically be line buffered if output is to the terminal and block
  193. buffered otherwise.  Setting this variable is useful primarily when you
  194. are outputting to a pipe, such as when you are running a Perl script
  195. under rsh and want to see the output as it's happening.  (Mnemonic:
  196. when you want your pipes to be piping hot.)
  197. <p></dd>
  198.  
  199. <dt><b><A NAME="perlvar_394">output_field_separator HANDLE EXPR</A></b>
  200.  
  201. <dt><b><A NAME="perlvar_395">$OUTPUT_FIELD_SEPARATOR</A></b>
  202.  
  203. <dt><b><A NAME="perlvar_396">$OFS</A></b>
  204.  
  205. <dt><b><A NAME="perlvar_397">$,</A></b>
  206. <dd>
  207. The output field separator for the print operator.  Ordinarily the
  208. print operator simply prints out the comma separated fields you
  209. specify.  In order to get behavior more like <B>awk</B>, set this variable
  210. as you would set <B>awk</B>'s OFS variable to specify what is printed
  211. between fields.  (Mnemonic: what is printed when there is a , in your
  212. print statement.)
  213. <p></dd>
  214.  
  215. <dt><b><A NAME="perlvar_398">output_record_separator HANDLE EXPR</A></b>
  216.  
  217. <dt><b><A NAME="perlvar_399">$OUTPUT_RECORD_SEPARATOR</A></b>
  218.  
  219. <dt><b><A NAME="perlvar_400">$ORS</A></b>
  220.  
  221. <dt><b><A NAME="perlvar_401">$\</A></b>
  222. <dd>
  223. The output record separator for the print operator.  Ordinarily the
  224. print operator simply prints out the comma separated fields you
  225. specify, with no trailing newline or record separator assumed.  In
  226. order to get behavior more like <B>awk</B>, set this variable as you would
  227. set <B>awk</B>'s ORS variable to specify what is printed at the end of the
  228. print.  (Mnemonic: you set "
  229. <A HREF="perlvar.html#perlvar_401">$\</A>
  230. " instead of adding \n at the end of the
  231. print.  Also, it's just like /, but it's what you get "back" from
  232. Perl.)
  233. <p></dd>
  234.  
  235. <dt><b><A NAME="perlvar_402">$LIST_SEPARATOR</A></b>
  236.  
  237. <dt><b><A NAME="perlvar_403">$"</A></b>
  238. <dd>
  239. This is like "
  240. <A HREF="perlvar.html#perlvar_397">$,</A>
  241. " except that it applies to array values interpolated
  242. into a double-quoted string (or similar interpreted string).  Default
  243. is a space.  (Mnemonic: obvious, I think.)
  244. <p></dd>
  245.  
  246. <dt><b><A NAME="perlvar_404">$SUBSCRIPT_SEPARATOR</A></b>
  247.  
  248. <dt><b><A NAME="perlvar_405">$SUBSEP</A></b>
  249.  
  250. <dt><b><A NAME="perlvar_406">$;</A></b>
  251. <dd>
  252. The subscript separator for multi-dimensional array emulation.  If you
  253. refer to a hash element as
  254. <p></dd>
  255. <pre>
  256.         $foo{$a,$b,$c}
  257. </pre>
  258. it really means
  259. <p><pre>
  260.         $foo{join($;, $a, $b, $c)}
  261. </pre>
  262. But don't put
  263. <p><pre>
  264.         @foo{$a,$b,$c}  # a slice--note the @
  265. </pre>
  266. which means
  267. <p><pre>
  268.         ($foo{$a},$foo{$b},$foo{$c})
  269. </pre>
  270. Default is "\034", the same as SUBSEP in <B>awk</B>.  Note that if your
  271. keys contain binary data there might not be any safe value for "
  272. <A HREF="perlvar.html#perlvar_406">$;</A>
  273. ".
  274. (Mnemonic: comma (the syntactic subscript separator) is a
  275. semi-semicolon.  Yeah, I know, it's pretty lame, but "
  276. <A HREF="perlvar.html#perlvar_397">$,</A>
  277. " is already
  278. taken for something more important.)
  279. <p>Consider using "real" multi-dimensional arrays in Perl 5.
  280. <p>
  281. <dt><b><A NAME="perlvar_407">$OFMT</A></b>
  282.  
  283. <dt><b><A NAME="perlvar_408">$#</A></b>
  284. <dd>
  285. The output format for printed numbers.  This variable is a half-hearted
  286. attempt to emulate <B>awk</B>'s OFMT variable.  There are times, however,
  287. when <B>awk</B> and Perl have differing notions of what is in fact
  288. numeric.  Also, the initial value is %.20g rather than %.6g, so you
  289. need to set "
  290. <A HREF="perlvar.html#perlvar_408">$#</A>
  291. " explicitly to get <B>awk</B>'s value.  (Mnemonic: # is the
  292. number sign.)
  293. <p></dd>
  294. Use of "
  295. <A HREF="perlvar.html#perlvar_408">$#</A>
  296. " is deprecated in Perl 5.
  297. <p>
  298. <dt><b><A NAME="perlvar_409">format_page_number HANDLE EXPR</A></b>
  299.  
  300. <dt><b><A NAME="perlvar_410">$FORMAT_PAGE_NUMBER</A></b>
  301.  
  302. <dt><b><A NAME="perlvar_411">$%</A></b>
  303. <dd>
  304. The current page number of the currently selected output channel.
  305. (Mnemonic: % is page number in <B>nroff</B>.)
  306. <p></dd>
  307.  
  308. <dt><b><A NAME="perlvar_412">format_lines_per_page HANDLE EXPR</A></b>
  309.  
  310. <dt><b><A NAME="perlvar_413">$FORMAT_LINES_PER_PAGE</A></b>
  311.  
  312. <dt><b><A NAME="perlvar_414">$=</A></b>
  313. <dd>
  314. The current page length (printable lines) of the currently selected
  315. output channel.  Default is 60.  (Mnemonic: = has horizontal lines.)
  316. <p></dd>
  317.  
  318. <dt><b><A NAME="perlvar_415">format_lines_left HANDLE EXPR</A></b>
  319.  
  320. <dt><b><A NAME="perlvar_416">$FORMAT_LINES_LEFT</A></b>
  321.  
  322. <dt><b><A NAME="perlvar_417">$-</A></b>
  323. <dd>
  324. The number of lines left on the page of the currently selected output
  325. channel.  (Mnemonic: lines_on_page - lines_printed.)
  326. <p></dd>
  327.  
  328. <dt><b><A NAME="perlvar_418">format_name HANDLE EXPR</A></b>
  329.  
  330. <dt><b><A NAME="perlvar_419">$FORMAT_NAME</A></b>
  331.  
  332. <dt><b><A NAME="perlvar_420">$~</A></b>
  333. <dd>
  334. The name of the current report format for the currently selected output
  335. channel.  Default is name of the filehandle.  (Mnemonic: brother to
  336. "
  337. <A HREF="perlvar.html#perlvar_423">$^</A>
  338. ".)
  339. <p></dd>
  340.  
  341. <dt><b><A NAME="perlvar_421">format_top_name HANDLE EXPR</A></b>
  342.  
  343. <dt><b><A NAME="perlvar_422">$FORMAT_TOP_NAME</A></b>
  344.  
  345. <dt><b><A NAME="perlvar_423">$^</A></b>
  346. <dd>
  347. The name of the current top-of-page format for the currently selected
  348. output channel.  Default is name of the filehandle with _TOP
  349. appended.  (Mnemonic: points to top of page.)
  350. <p></dd>
  351.  
  352. <dt><b><A NAME="perlvar_424">format_line_break_characters HANDLE EXPR</A></b>
  353.  
  354. <dt><b><A NAME="perlvar_425">$FORMAT_LINE_BREAK_CHARACTERS</A></b>
  355.  
  356. <dt><b><A NAME="perlvar_426">$:</A></b>
  357. <dd>
  358. The current set of characters after which a string may be broken to
  359. fill continuation fields (starting with ^) in a format.  Default is 
  360. " \n-", to break on whitespace or hyphens.  (Mnemonic: a "colon" in
  361. poetry is a part of a line.)
  362. <p></dd>
  363.  
  364. <dt><b><A NAME="perlvar_427">format_formfeed HANDLE EXPR</A></b>
  365.  
  366. <dt><b><A NAME="perlvar_428">$FORMAT_FORMFEED</A></b>
  367.  
  368. <dt><b><A NAME="perlvar_429">$^L</A></b>
  369. <dd>
  370. What formats output to perform a formfeed.  Default is \f.
  371. <p></dd>
  372.  
  373. <dt><b><A NAME="perlvar_430">$ACCUMULATOR</A></b>
  374.  
  375. <dt><b><A NAME="perlvar_431">$^A</A></b>
  376. <dd>
  377. The current value of the write() accumulator for format() lines.  A format
  378. contains formline() commands that put their result into 
  379. <A HREF="perlvar.html#perlvar_431">$^A</A>
  380. .  After
  381. calling its format, write() prints out the contents of 
  382. <A HREF="perlvar.html#perlvar_431">$^A</A>
  383.  and empties.
  384. So you never actually see the contents of 
  385. <A HREF="perlvar.html#perlvar_431">$^A</A>
  386.  unless you call
  387. formline() yourself and then look at it.  See 
  388. <A HREF="perlform.html">
  389. the perlform manpage</A>
  390.  and
  391. perlfunc/formline().
  392. <p></dd>
  393.  
  394. <dt><b><A NAME="perlvar_432">$CHILD_ERROR</A></b>
  395.  
  396. <dt><b><A NAME="perlvar_433">$?</A></b>
  397. <dd>
  398. The status returned by the last pipe close, backtick (<B>``</B>) command,
  399. or system() operator.  Note that this is the status word returned by
  400. the wait() system call, so the exit value of the subprocess is actually
  401. (<B>$? >> 8</B>).  Thus on many systems, <B>$? & 255</B> gives which signal,
  402. if any, the process died from, and whether there was a core dump.
  403. (Mnemonic: similar to <B>sh</B> and <B>ksh</B>.)
  404. <p></dd>
  405.  
  406. <dt><b><A NAME="perlvar_434">$OS_ERROR</A></b>
  407.  
  408. <dt><b><A NAME="perlvar_435">$ERRNO</A></b>
  409.  
  410. <dt><b><A NAME="perlvar_436">$!</A></b>
  411. <dd>
  412. If used in a numeric context, yields the current value of errno, with
  413. all the usual caveats.  (This means that you shouldn't depend on the
  414. value of "
  415. <A HREF="perlvar.html#perlvar_436">$!</A>
  416. " to be anything in particular unless you've gotten a
  417. specific error return indicating a system error.)  If used in a string
  418. context, yields the corresponding system error string.  You can assign
  419. to "
  420. <A HREF="perlvar.html#perlvar_436">$!</A>
  421. " in order to set <I>errno</I> if, for instance, you want "
  422. <A HREF="perlvar.html#perlvar_436">$!</A>
  423. " to return the
  424. string for error <I>n</I>, or you want to set the exit value for the die()
  425. operator.  (Mnemonic: What just went bang?)
  426. <p></dd>
  427.  
  428. <dt><b><A NAME="perlvar_437">$EVAL_ERROR</A></b>
  429.  
  430. <dt><b><A NAME="perlvar_438">$@</A></b>
  431. <dd>
  432. The Perl syntax error message from the last eval() command.  If null, the
  433. last eval() parsed and executed correctly (although the operations you
  434. invoked may have failed in the normal fashion).  (Mnemonic: Where was
  435. the syntax error "at"?)
  436. <p></dd>
  437.  
  438. <dt><b><A NAME="perlvar_439">$PROCESS_ID</A></b>
  439.  
  440. <dt><b><A NAME="perlvar_440">$PID</A></b>
  441.  
  442. <dt><b><A NAME="perlvar_441">$$</A></b>
  443. <dd>
  444. The process number of the Perl running this script.  (Mnemonic: same
  445. as shells.)
  446. <p></dd>
  447.  
  448. <dt><b><A NAME="perlvar_442">$REAL_USER_ID</A></b>
  449.  
  450. <dt><b><A NAME="perlvar_443">$UID</A></b>
  451. <dt><B>$<</B>
  452. <dd>
  453. The real uid of this process.  (Mnemonic: it's the uid you came <I>FROM</I>,
  454. if you're running setuid.)
  455. <p></dd>
  456.  
  457. <dt><b><A NAME="perlvar_445">$EFFECTIVE_USER_ID</A></b>
  458.  
  459. <dt><b><A NAME="perlvar_446">$EUID</A></b>
  460. <dt><B>$></B>
  461. <dd>
  462. The effective uid of this process.  Example:
  463. <p></dd>
  464. <pre>
  465.         $< = $>;          # set real to effective uid
  466.         ($<,$>) = ($>,$<);  # swap real and effective uid
  467. </pre>
  468. (Mnemonic: it's the uid you went <I>TO</I>, if you're running setuid.)  Note:
  469. "<B>$<</B>" and "<B>$></B>" can only be swapped on machines supporting setreuid().
  470. <p>
  471. <dt><b><A NAME="perlvar_448">$REAL_GROUP_ID</A></b>
  472.  
  473. <dt><b><A NAME="perlvar_449">$GID</A></b>
  474.  
  475. <dt><b><A NAME="perlvar_450">$(</A></b>
  476. <dd>
  477. The real gid of this process.  If you are on a machine that supports
  478. membership in multiple groups simultaneously, gives a space separated
  479. list of groups you are in.  The first number is the one returned by
  480. getgid(), and the subsequent ones by getgroups(), one of which may be
  481. the same as the first number.  (Mnemonic: parentheses are used to <I>GROUP</I>
  482. things.  The real gid is the group you <I>LEFT</I>, if you're running setgid.)
  483. <p></dd>
  484.  
  485. <dt><b><A NAME="perlvar_451">$EFFECTIVE_GROUP_ID</A></b>
  486.  
  487. <dt><b><A NAME="perlvar_452">$EGID</A></b>
  488.  
  489. <dt><b><A NAME="perlvar_453">$)</A></b>
  490. <dd>
  491. The effective gid of this process.  If you are on a machine that
  492. supports membership in multiple groups simultaneously, gives a space
  493. separated list of groups you are in.  The first number is the one
  494. returned by getegid(), and the subsequent ones by getgroups(), one of
  495. which may be the same as the first number.  (Mnemonic: parentheses are
  496. used to <I>GROUP</I> things.  The effective gid is the group that's <I>RIGHT</I> for
  497. you, if you're running setgid.)
  498. <p></dd>
  499. Note: "<B>$<</B>", "<B>$></B>", "
  500. <A HREF="perlvar.html#perlvar_450">$(</A>
  501. " and "
  502. <A HREF="perlvar.html#perlvar_453">$)</A>
  503. " can only be set on machines
  504. that support the corresponding <I>set[re][ug]id()</I> routine.  "
  505. <A HREF="perlvar.html#perlvar_450">$(</A>
  506. " and "
  507. <A HREF="perlvar.html#perlvar_453">$)</A>
  508. can only be swapped on machines supporting setregid().
  509. <p>
  510. <dt><b><A NAME="perlvar_454">$PROGRAM_NAME</A></b>
  511.  
  512. <dt><b><A NAME="perlvar_455">$0</A></b>
  513. <dd>
  514. Contains the name of the file containing the Perl script being
  515. executed.  Assigning to "
  516. <A HREF="perlvar.html#perlvar_455">$0</A>
  517. " modifies the argument area that the ps(1)
  518. program sees.  This is more useful as a way of indicating the
  519. current program state than it is for hiding the program you're running.
  520. (Mnemonic: same as <B>sh</B> and <B>ksh</B>.)
  521. <p></dd>
  522.  
  523. <dt><b><A NAME="perlvar_456">$[</A></b>
  524. <dd>
  525. The index of the first element in an array, and of the first character
  526. in a substring.  Default is 0, but you could set it to 1 to make
  527. Perl behave more like <B>awk</B> (or Fortran) when subscripting and when
  528. evaluating the index() and substr() functions.  (Mnemonic: [ begins
  529. subscripts.)
  530. <p></dd>
  531. As of Perl 5, assignment to "
  532. <A HREF="perlvar.html#perlvar_456">$[</A>
  533. " is treated as a compiler directive,
  534. and cannot influence the behavior of any other file.  Its use is
  535. discouraged.
  536. <p>
  537. <dt><b><A NAME="perlvar_457">$PERL_VERSION</A></b>
  538.  
  539. <dt><b><A NAME="perlvar_458">$]</A></b>
  540. <dd>
  541. The string printed out when you say <B>perl -v</B>.  It can be used to
  542. determine at the beginning of a script whether the perl interpreter
  543. executing the script is in the right range of versions.  If used in a
  544. numeric context, returns the version + patchlevel / 1000.  Example:
  545. <p></dd>
  546. <pre>
  547.         # see if getc is available
  548.         ($version,$patchlevel) =
  549.              $] =~ /(\d+\.\d+).*\nPatch level: (\d+)/;
  550.         print STDERR "(No filename completion available.)\n"
  551.              if $version * 1000 + $patchlevel < 2016;
  552. </pre>
  553. or, used numerically,
  554. <p><pre>
  555.         warn "No checksumming!\n" if $] < 3.019;
  556. </pre>
  557. (Mnemonic: Is this version of perl in the right bracket?)
  558. <p>
  559. <dt><b><A NAME="perlvar_459">$DEBUGGING</A></b>
  560.  
  561. <dt><b><A NAME="perlvar_460">$^D</A></b>
  562. <dd>
  563. The current value of the debugging flags.  (Mnemonic: value of 
  564. <A HREF="perlrun.html#perlrun_347">-D</A>
  565.  
  566. switch.)
  567. <p></dd>
  568.  
  569. <dt><b><A NAME="perlvar_461">$SYSTEM_FD_MAX</A></b>
  570.  
  571. <dt><b><A NAME="perlvar_462">$^F</A></b>
  572. <dd>
  573. The maximum system file descriptor, ordinarily 2.  System file
  574. descriptors are passed to exec()ed processes, while higher file
  575. descriptors are not.  Also, during an open(), system file descriptors are
  576. preserved even if the open() fails.  (Ordinary file descriptors are
  577. closed before the open() is attempted.)  Note that the close-on-exec
  578. status of a file descriptor will be decided according to the value of
  579.  
  580. <A HREF="perlvar.html#perlvar_462">$^F</A>
  581.  at the time of the open, not the time of the exec.
  582. <p></dd>
  583.  
  584. <dt><b><A NAME="perlvar_463">$INPLACE_EDIT</A></b>
  585.  
  586. <dt><b><A NAME="perlvar_464">$^I</A></b>
  587. <dd>
  588. The current value of the inplace-edit extension.  Use 
  589. <A HREF="perlfunc.html#perlfunc_258">undef</A>
  590.  to disable
  591. inplace editing.  (Mnemonic: value of 
  592. <A HREF="perlrun.html#perlrun_350">-i</A>
  593.  switch.)
  594. <p></dd>
  595.  
  596. <dt><b><A NAME="perlvar_465">$PERLDB</A></b>
  597.  
  598. <dt><b><A NAME="perlvar_466">$^P</A></b>
  599. <dd>
  600. The internal flag that the debugger clears so that it doesn't debug
  601. itself.  You could conceivable disable debugging yourself by clearing
  602. it.
  603. <p></dd>
  604.  
  605. <dt><b><A NAME="perlvar_467">$BASETIME</A></b>
  606.  
  607. <dt><b><A NAME="perlvar_468">$^T</A></b>
  608. <dd>
  609. The time at which the script began running, in seconds since the
  610. epoch (beginning of 1970).  The values returned by the <B>-M</B>, <B>-A</B> 
  611. and <B>-C</B> filetests are
  612. based on this value.
  613. <p></dd>
  614.  
  615. <dt><b><A NAME="perlvar_469">$WARNING</A></b>
  616.  
  617. <dt><b><A NAME="perlvar_470">$^W</A></b>
  618. <dd>
  619. The current value of the warning switch, either TRUE or FALSE.  (Mnemonic: related to the
  620.  
  621. <A HREF="perlrun.html#perlrun_362">-w</A>
  622.  switch.)
  623. <p></dd>
  624.  
  625. <dt><b><A NAME="perlvar_471">$EXECUTABLE_NAME</A></b>
  626.  
  627. <dt><b><A NAME="perlvar_472">$^X</A></b>
  628. <dd>
  629. The name that the Perl binary itself was executed as, from C's <B>argv[0]</B>.
  630. <p></dd>
  631.  
  632. <dt><b><A NAME="perlvar_473">$ARGV</A></b>
  633. <dd>
  634. contains the name of the current file when reading from <>.
  635. <p></dd>
  636.  
  637. <dt><b><A NAME="perlvar_474">@ARGV</A></b>
  638. <dd>
  639. The array @ARGV contains the command line arguments intended for the
  640. script.  Note that <B>$#ARGV</B> is the generally number of arguments minus
  641. one, since <B>$ARGV[0]</B> is the first argument, <I>NOT</I> the command name.  See
  642. "
  643. <A HREF="perlvar.html#perlvar_455">$0</A>
  644. " for the command name.
  645. <p></dd>
  646.  
  647. <dt><b><A NAME="perlvar_475">@INC</A></b>
  648. <dd>
  649. The array @INC contains the list of places to look for Perl scripts to
  650. be evaluated by the <B>do EXPR</B>, 
  651. <A HREF="perlfunc.html#perlfunc_205">require</A>
  652. , or 
  653. <A HREF="perlfunc.html#perlfunc_263">use</A>
  654.  constructs.  It
  655. initially consists of the arguments to any 
  656. <A HREF="perlrun.html#perlrun_351">-I</A>
  657.  command line switches,
  658. followed by the default Perl library, probably "/usr/local/lib/perl",
  659. followed by ".", to represent the current directory.
  660. <p></dd>
  661.  
  662. <dt><b><A NAME="perlvar_476">%INC</A></b>
  663. <dd>
  664. The hash %INC contains entries for each filename that has
  665. been included via 
  666. <A HREF="perlfunc.html#perlfunc_97">do</A>
  667.  or 
  668. <A HREF="perlfunc.html#perlfunc_205">require</A>
  669. .  The key is the filename you
  670. specified, and the value is the location of the file actually found.
  671. The 
  672. <A HREF="perlfunc.html#perlfunc_205">require</A>
  673.  command uses this array to determine whether a given file
  674. has already been included.
  675. <p></dd>
  676.  
  677. <dt><b><A NAME="perlvar_477">$ENV{expr}</A></b>
  678. <dd>
  679. The hash %ENV contains your current environment.  Setting a
  680. value in <B>ENV</B> changes the environment for child processes.
  681. <p></dd>
  682.  
  683. <dt><b><A NAME="perlvar_478">$SIG{expr}</A></b>
  684. <dd>
  685. The hash %SIG is used to set signal handlers for various
  686. signals.  Example:
  687. <p></dd>
  688. <pre>
  689.         sub handler {   # 1st argument is signal name
  690.         local($sig) = @_;
  691.         print "Caught a SIG$sig--shutting down\n";
  692.         close(LOG);
  693.         exit(0);
  694.         }
  695. </pre>
  696. <pre>
  697.         $SIG{'INT'} = 'handler';
  698.         $SIG{'QUIT'} = 'handler';
  699.         ...
  700.         $SIG{'INT'} = 'DEFAULT';        # restore default action
  701.         $SIG{'QUIT'} = 'IGNORE';        # ignore SIGQUIT
  702. </pre>
  703. The %SIG array only contains values for the signals actually set within
  704. the Perl script.  Here are some other examples:
  705. <p><pre>
  706.         $SIG{PIPE} = Plumber;       # SCARY!!
  707.         $SIG{"PIPE"} = "Plumber";   # just fine, assumes main::Plumber
  708.         $SIG{"PIPE"} = \&Plumber;   # just fine; assume current Plumber
  709.         $SIG{"PIPE"} = Plumber();   # oops, what did Plumber() return??
  710. </pre>
  711. The one marked scary is problematic because it's a bareword, which means
  712. sometimes it's a string representing the function, and sometimes it's 
  713. going to call the subroutine call right then and there!  Best to be sure
  714. and quote it or take a reference to it.  *Plumber works too.  See <perlsubs>.
  715. <p>
  716. </dl>
  717.  
  718.  
  719. </HTML>
  720.