The following names have special meaning to perl. I could have used alphabetic symbols for some of these, but I didn't want to take the chance that someone would say `reset "a-zA-Z"' and wipe them all out. You'll just have to suffer along with these silly symbols. Most of them have reasonable mnemonics, or analogues in one of the shells.
while (<>) {... # only equivalent in while! while ($_ = <>) {... /^Subject:/ $_ =~ /^Subject:/ y/a-z/A-Z/ $_ =~ y/a-z/A-Z/ chop chop($_)(Mnemonic: underline is understood in certain operations.)
eof
). (Mnemonic: many programs use `.' to mean the current
line number.)
awk
's
RS variable, including treating blank lines as delimiters if set to the
null string. You may set it to a multicharacter string to match a
multi-character delimiter.
Note that setting it to "\n\n"
means something slightly different
than setting it to ""
, if the file contains consecutive blank
lines. Setting it to ""
will treat two or more consecutive blank
lines as a single blank line.
Setting it to "\en\en" will blindly assume that the next input character
belongs to the next paragraph, even if it's a newline.
(Mnemonic: `/' is used to delimit line
boundaries when quoting poetry.)
print
operator. Ordinarily the
print
operator simply prints out the comma separated fields you
specify. In order to get behavior more like awk
, set this variable
as you would set awk
's OFS variable to specify what is printed
between fields. (Mnemonic: what is printed when there is a `,' in
your print statement.)
print
operator. Ordinarily the
print
operator simply prints out the comma separated fields you specify,
with no trailing newline or record separator assumed. In order to get
behavior more like awk
, set this variable as you would set
awk
's ORS variable to specify what is printed at the end of the
print. (Mnemonic: you set `$\' instead of adding `\n' at the
end of the print. Also, it's just like `/', but it's what you get
"back" from perl.)
awk
's OFMT variable. There are times,
however, when awk
and perl have differing notions of what
is in fact numeric. Also, the initial value is `%.20g' rather than
`%.6g', so you need to set `$#' explicitly to get awk
's
value. (Mnemonic: `#' is the number sign.)
_TOP
appended. (Mnemonic: points to top of page.)
write
or print
on the currently selected output channel. Default is 0. Note that
`STDOUT' will typically be line buffered if output is to the terminal
and block buffered otherwise. Setting this variable is useful primarily
when you are outputting to a pipe, such as when you are running a
perl script under rsh and want to see the output as it's happening.
(Mnemonic: when you want your pipes to be piping hot.)
system
operator. Note that this is the status word returned by
the wait()
system call, so the exit value of the subprocess is
actually `($? >> 8)'. `$? & 255' gives which signal, if any,
the process died from, and whether there was a core dump. (Mnemonic:
similar to sh
and ksh
.)
eval
enclosed by the current BLOCK).
(Mnemonic: like `&' in some editors.)
eval
enclosed by
the current BLOCK). (Mnemonic: ` often precedes a quoted
string.)
eval
enclosed by
the current BLOCK). (Mnemonic: ' often follows a quoted string.)
Example:
$_ = 'abcdefghi'; /def/; print "$`:$&:$'\n"; # prints abc:def:ghi
/Version: (.*)|Revision: (.*)/ && ($rev = $+);(Mnemonic: be positive and forward looking.)
ps(1)
program sees. (Mnemonic: same as sh
and
ksh
.)
awk
(or Fortran) when subscripting
and when evaluating the index()
and substr()
functions.
(Mnemonic: `[' begins subscripts.)
# see if getc is available ($version,$patchlevel) = $] =~ /(\d+\.\d+).*\nPatch level: (\d+)/; print STDERR "(No filename completion available.)\n" if $version * 1000 + $patchlevel < 2016;or, used numerically,
warn "No checksumming!\n" if $] < 3.019;(Mnemonic: Is this version of perl in the right bracket?)
$foo{$a,$b,$c}it really means
$foo{join($;, $a, $b, $c)}But don't put
@foo{$a,$b,$c} # a slice--note the @which means
($foo{$a},$foo{$b},$foo{$c})Default is `\034', the same as SUBSEP in
awk
. Note that if
your keys contain binary data there might not be any safe value for
`$;'. (Mnemonic: comma (the syntactic subscript separator) is a
semi-semicolon. Yeah, I know, it's pretty lame, but `$,' is
already taken for something more important.)
die
operator. (Mnemonic: What just went bang?)
eval
command. If null,
the last eval
parsed and executed correctly (although the
operations you invoked may have failed in the normal fashion). (Mnemonic:
Where was the syntax error "at"?)
$< = $>; # set real uid to the effective uid ($<,$>) = ($>,$<); # swap real and effective uid(Mnemonic: it's the uid you went TO, if you're running setuid.) Note: `$<' and `$>' can only be swapped on machines supporting
setreuid()
.
getgid()
, and the subsequent ones by getgroups()
, one of
which may be the same as the first number. (Mnemonic: parentheses are
used to GROUP things. The real gid is the group you
LEFT, if you're running setgid.)
getegid()
, and the subsequent ones by getgroups()
, one of
which may be the same as the first number. (Mnemonic: parentheses are
used to GROUP things. The effective gid is the group that's
RIGHT for you, if you're running setgid.)
Note: `$<', `$>', `$(' and `$)' can only be set on
machines that support the corresponding set[re][ug]id()
routine.
`$(' and `$)' can only be swapped on machines supporting
setregid()
.
undef
to
disable inplace editing. (Mnemonic: value of `-i' switch.)
do EXPR
command or the
require
command. It initially consists of the arguments to any
`-I' command line switches, followed by the default perl
library, probably `/usr/local/lib/perl', followed by `.', to
represent the current directory.
do
or require
. The key is the
filename you specified, and the value is the location of the file
actually found. The require
command uses this array to determine
whether a given file has already been included.
sub handler { # 1st argument is signal name local($sig) = @_; print "Caught a SIG$sig--shutting down\n"; close(LOG); exit(0); } $SIG{'INT'} = 'handler'; $SIG{'QUIT'} = 'handler'; ... $SIG{'INT'} = 'DEFAULT'; # restore default action $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUITThe `SIG' array only contains values for the signals actually set within the perl script.