home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Magazin: Amiga-CD 1996 July
/
AMIGA_1996_7.BIN
/
ausgabe_7_96
/
pd-programmierung
/
perl5_002bin.lha
/
man
/
catp
/
perltrap.0
< prev
next >
Wrap
Text File
|
1996-03-02
|
21KB
|
529 lines
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
NNNNAAAAMMMMEEEE
perltrap - Perl traps for the unwary
DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
The biggest trap of all is forgetting to use the ----wwww
switch; see the _p_e_r_l_r_u_n manpage. The second biggest trap
is not making your entire program runnable under uuuusssseeee
ssssttttrrrriiiicccctttt.
AAAAwwwwkkkk TTTTrrrraaaappppssss
Accustomed aaaawwwwkkkk users should take special note of the
following:
+o The English module, loaded via
uuuusssseeee EEEEnnnngggglllliiiisssshhhh;;;;
allows you to refer to special variables (like $$$$RRRRSSSS) as
though they were in aaaawwwwkkkk; see the _p_e_r_l_v_a_r manpage for
details.
+o Semicolons are required after all simple statements in
Perl (except at the end of a block). Newline is not a
statement delimiter.
+o Curly brackets are required on iiiiffffs and wwwwhhhhiiiilllleeees.
+o Variables begin with "$" or "@" in Perl.
+o Arrays index from 0. Likewise string positions in
_s_u_b_s_t_r_(_) and _i_n_d_e_x_(_).
+o You have to decide whether your array has numeric or
string indices.
+o Associative array values do not spring into existence
upon mere reference.
+o You have to decide whether you want to use string or
numeric comparisons.
+o Reading an input line does not split it for you. You
get to split it yourself to an array. And _s_p_l_i_t_(_)
operator has different arguments.
+o The current input line is normally in $$$$____, not $$$$0000. It
generally does not have the newline stripped. ($0 is
the name of the program executed.) See the _p_e_r_l_v_a_r
manpage.
+o $<_d_i_g_i_t> does not refer to fields--it refers to
substrings matched by the last match pattern.
30/Jan/96 perl 5.002 with 1
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
+o The _p_r_i_n_t_(_) statement does not add field and record
separators unless you set $$$$,,,, and $$$$..... You can set $$$$OOOOFFFFSSSS
and $$$$OOOORRRRSSSS if you're using the English module.
+o You must open your files before you print to them.
+o The range operator is "..", not comma. The comma
operator works as in C.
+o The match operator is "=~", not "~". ("~" is the
one's complement operator, as in C.)
+o The exponentiation operator is "**", not "^". "^" is
the XOR operator, as in C. (You know, one could get
the feeling that aaaawwwwkkkk is basically incompatible with
C.)
+o The concatenation operator is ".", not the null
string. (Using the null string would render ////ppppaaaatttt////
////ppppaaaatttt//// unparsable, since the third slash would be
interpreted as a division operator--the tokener is in
fact slightly context sensitive for operators like
"/", "?", and ">". And in fact, "." itself can be the
beginning of a number.)
+o The nnnneeeexxxxtttt, eeeexxxxiiiitttt, and ccccoooonnnnttttiiiinnnnuuuueeee keywords work
differently.
+o The following variables work differently:
AAAAwwwwkkkk PPPPeeeerrrrllll
AAAARRRRGGGGCCCC $$$$####AAAARRRRGGGGVVVV oooorrrr ssssccccaaaallllaaaarrrr @@@@AAAARRRRGGGGVVVV
AAAARRRRGGGGVVVV[[[[0000]]]] $$$$0000
FFFFIIIILLLLEEEENNNNAAAAMMMMEEEE $$$$AAAARRRRGGGGVVVV
FFFFNNNNRRRR $$$$.... ---- ssssoooommmmeeeetttthhhhiiiinnnngggg
FFFFSSSS ((((wwwwhhhhaaaatttteeeevvvveeeerrrr yyyyoooouuuu lllliiiikkkkeeee))))
NNNNFFFF $$$$####FFFFlllldddd,,,, oooorrrr ssssoooommmmeeee ssssuuuucccchhhh
NNNNRRRR $$$$....
OOOOFFFFMMMMTTTT $$$$####
OOOOFFFFSSSS $$$$,,,,
OOOORRRRSSSS $$$$\\\\
RRRRLLLLEEEENNNNGGGGTTTTHHHH lllleeeennnnggggtttthhhh(((($$$$&&&&))))
RRRRSSSS $$$$////
RRRRSSSSTTTTAAAARRRRTTTT lllleeeennnnggggtttthhhh(((($$$$````))))
SSSSUUUUBBBBSSSSEEEEPPPP $$$$;;;;
+o You cannot set $$$$RRRRSSSS to a pattern, only a string.
+o When in doubt, run the aaaawwwwkkkk construct through aaaa2222pppp and
see what it gives you.
30/Jan/96 perl 5.002 with 2
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
CCCC TTTTrrrraaaappppssss
Cerebral C programmers should take note of the following:
+o Curly brackets are required on iiiiffff's and wwwwhhhhiiiilllleeee's.
+o You must use eeeellllssssiiiiffff rather than eeeellllsssseeee iiiiffff.
+o The bbbbrrrreeeeaaaakkkk and ccccoooonnnnttttiiiinnnnuuuueeee keywords from C become in Perl
llllaaaasssstttt and nnnneeeexxxxtttt, respectively. Unlike in C, these do
_N_O_T work within a ddddoooo {{{{ }}}} wwwwhhhhiiiilllleeee construct.
+o There's no switch statement. (But it's easy to build
one on the fly.)
+o Variables begin with "$" or "@" in Perl.
+o _p_r_i_n_t_f_(_) does not implement the "*" format for
interpolating field widths, but it's trivial to use
interpolation of double-quoted strings to achieve the
same effect.
+o Comments begin with "#", not "/*".
+o You can't take the address of anything, although a
similar operator in Perl 5 is the backslash, which
creates a reference.
+o AAAARRRRGGGGVVVV must be capitalized. $$$$AAAARRRRGGGGVVVV[[[[0000]]]] is C's aaaarrrrggggvvvv[[[[1111]]]],
and aaaarrrrggggvvvv[[[[0000]]]] ends up in $$$$0000.
+o System calls such as _l_i_n_k_(_), _u_n_l_i_n_k_(_), _r_e_n_a_m_e_(_), etc.
return nonzero for success, not 0.
+o Signal handlers deal with signal names, not numbers.
Use kkkkiiiillllllll ----llll to find their names on your system.
SSSSeeeedddd TTTTrrrraaaappppssss
Seasoned sssseeeedddd programmers should take note of the
following:
+o Backreferences in substitutions use "$" rather than
"\".
+o The pattern matching metacharacters "(", ")", and "|"
do not have backslashes in front.
+o The range operator is ............, rather than comma.
SSSShhhheeeellllllll TTTTrrrraaaappppssss
Sharp shell programmers should take note of the following:
30/Jan/96 perl 5.002 with 3
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
+o The backtick operator does variable interpretation
without regard to the presence of single quotes in the
command.
+o The backtick operator does no translation of the
return value, unlike ccccsssshhhh.
+o Shells (especially ccccsssshhhh) do several levels of
substitution on each command line. Perl does
substitution only in certain constructs such as double
quotes, backticks, angle brackets, and search
patterns.
+o Shells interpret scripts a little bit at a time. Perl
compiles the entire program before executing it
(except for BBBBEEEEGGGGIIIINNNN blocks, which execute at compile
time).
+o The arguments are available via @@@@AAAARRRRGGGGVVVV, not $$$$1111, $$$$2222,
etc.
+o The environment is not automatically made available as
separate scalar variables.
PPPPeeeerrrrllll TTTTrrrraaaappppssss
Practicing Perl Programmers should take note of the
following:
+o Remember that many operations behave differently in a
list context than they do in a scalar one. See the
_p_e_r_l_d_a_t_a manpage for details.
+o Avoid barewords if you can, especially all lower-case
ones. You can't tell just by looking at it whether a
bareword is a function or a string. By using quotes
on strings and parens on function calls, you won't
ever get them confused.
+o You cannot discern from mere inspection which built-
ins are unary operators (like _c_h_o_p_(_) and _c_h_d_i_r_(_)) and
which are list operators (like _p_r_i_n_t_(_) and _u_n_l_i_n_k_(_)).
(User-defined subroutines can oooonnnnllllyyyy be list operators,
never unary ones.) See the _p_e_r_l_o_p manpage.
+o People have a hard time remembering that some
functions default to $$$$____, or @@@@AAAARRRRGGGGVVVV, or whatever, but
that others which you might expect to do not.
+o The <FH> construct is not the name of the filehandle,
it is a readline operation on that handle. The data
read is only assigned to $$$$____ if the file read is the
sole condition in a while loop:
30/Jan/96 perl 5.002 with 4
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
wwwwhhhhiiiilllleeee ((((<<<<FFFFHHHH>>>>)))) {{{{ }}}}
wwwwhhhhiiiilllleeee (((($$$$____ ==== <<<<FFFFHHHH>>>>)))) {{{{ }}}}........
<<<<FFFFHHHH>>>>;;;; #### ddddaaaattttaaaa ddddiiiissssccccaaaarrrrddddeeeedddd!!!!
+o Remember not to use "====" when you need "====~~~~"; these two
constructs are quite different:
$$$$xxxx ==== ////ffffoooooooo////;;;;
$$$$xxxx ====~~~~ ////ffffoooooooo////;;;;
+o The ddddoooo {{{{}}}} construct isn't a real loop that you can use
loop control on.
+o Use _m_y_(_) for local variables whenever you can get away
with it (but see the _p_e_r_l_f_o_r_m manpage for where you
can't). Using _l_o_c_a_l_(_) actually gives a local value to
a global variable, which leaves you open to unforeseen
side-effects of dynamic scoping.
+o If you localize an exported variable in a module, its
exported value will not change. The local name
becomes an alias to a new value but the external name
is still an alias for the original.
PPPPeeeerrrrllll4444 TTTTrrrraaaappppssss
Penitent Perl 4 Programmers should take note of the
following incompatible changes that occurred between
release 4 and release 5:
+o @@@@ now always interpolates an array in double-quotish
strings. Some programs may now need to use backslash
to protect any @@@@ that shouldn't interpolate.
+o Barewords that used to look like strings to Perl will
now look like subroutine calls if a subroutine by that
name is defined before the compiler sees them. For
example:
ssssuuuubbbb SSSSeeeeeeeeYYYYaaaa {{{{ ddddiiiieeee """"HHHHaaaassssttttaaaa llllaaaa vvvviiiissssttttaaaa,,,, bbbbaaaabbbbyyyy!!!!"""" }}}}
$$$$SSSSIIIIGGGG{{{{''''QQQQUUUUIIIITTTT''''}}}} ==== SSSSeeeeeeeeYYYYaaaa;;;;
In Perl 4, that set the signal handler; in Perl 5, it
actually calls the function! You may use the ----wwww
switch to find such places.
+o Symbols starting with ____ are no longer forced into
package mmmmaaaaiiiinnnn, except for $$$$____ itself (and @@@@____, etc.).
+o Double-colon is now a valid package separator in an
identifier. Thus these behave differently in perl4
vs. perl5:
30/Jan/96 perl 5.002 with 5
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
pppprrrriiiinnnntttt """"$$$$aaaa::::::::$$$$bbbb::::::::$$$$cccc\\\\nnnn"""";;;;
pppprrrriiiinnnntttt """"$$$$vvvvaaaarrrr::::::::aaaabbbbcccc::::::::xxxxyyyyzzzz\\\\nnnn"""";;;;
+o ssss''''$$$$llllhhhhssss''''$$$$rrrrhhhhssss'''' now does no interpolation on either side.
It used to interpolate $$$$llllhhhhssss but not $$$$rrrrhhhhssss.
+o The second and third arguments of _s_p_l_i_c_e_(_) are now
evaluated in scalar context (as the book says) rather
than list context.
+o These are now semantic errors because of precedence:
sssshhhhiiiifffftttt @@@@lllliiiisssstttt ++++ 22220000;;;;
$$$$nnnn ==== kkkkeeeeyyyyssss %%%%mmmmaaaapppp ++++ 22220000;;;;
Because if that were to work, then this couldn't:
sssslllleeeeeeeepppp $$$$ddddoooorrrrmmmmaaaannnnccccyyyy ++++ 22220000;;;;
+o The precedence of assignment operators is now the same
as the precedence of assignment. Perl 4 mistakenly
gave them the precedence of the associated operator.
So you now must parenthesize them in expressions like
////ffffoooooooo//// ???? (((($$$$aaaa ++++==== 2222)))) :::: (((($$$$aaaa ----==== 2222))));;;;
Otherwise
////ffffoooooooo//// ???? $$$$aaaa ++++==== 2222 :::: $$$$aaaa ----==== 2222;;;;
would be erroneously parsed as
((((////ffffoooooooo//// ???? $$$$aaaa ++++==== 2222 :::: $$$$aaaa)))) ----==== 2222;;;;
On the other hand,
$$$$aaaa ++++==== ////ffffoooooooo//// ???? 1111 :::: 2222;;;;
now works as a C programmer would expect.
+o ooooppppeeeennnn FFFFOOOOOOOO |||||||| ddddiiiieeee is now incorrect. You need parens
around the filehandle. While temporarily supported,
using such a construct will generate a non-fatal (but
non-suppressible) warning.
+o The elements of argument lists for formats are now
evaluated in list context. This means you can
interpolate list values now.
+o You can't do a ggggoooottttoooo into a block that is optimized
away. Darn.
30/Jan/96 perl 5.002 with 6
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
+o It is no longer syntactically legal to use whitespace
as the name of a variable, or as a delimiter for any
kind of quote construct. Double darn.
+o The _c_a_l_l_e_r_(_) function now returns a false value in a
scalar context if there is no caller. This lets
library files determine if they're being required.
+o mmmm////////gggg now attaches its state to the searched string
rather than the regular expression.
+o rrrreeeevvvveeeerrrrsssseeee is no longer allowed as the name of a sort
subroutine.
+o ttttaaaaiiiinnnnttttppppeeeerrrrllll is no longer a separate executable. There
is now a ----TTTT switch to turn on tainting when it isn't
turned on automatically.
+o Double-quoted strings may no longer end with an
unescaped $$$$ or @@@@.
+o The archaic wwwwhhhhiiiilllleeee////iiiiffff BLOCK BLOCK syntax is no longer
supported.
+o Negative array subscripts now count from the end of
the array.
+o The comma operator in a scalar context is now
guaranteed to give a scalar context to its arguments.
+o The ******** operator now binds more tightly than unary
minus. It was documented to work this way before, but
didn't.
+o Setting $$$$####aaaarrrrrrrraaaayyyy lower now discards array elements.
+o _d_e_l_e_t_e_(_) is not guaranteed to return the old value for
_t_i_e_(_)d arrays, since this capability may be onerous
for some modules to implement.
+o The construct "this is $$x" used to interpolate the
pid at that point, but now tries to dereference $$$$xxxx.
$$$$$$$$ by itself still works fine, however.
+o The meaning of foreach has changed slightly when it is
iterating over a list which is not an array. This
used to assign the list to a temporary array, but no
longer does so (for efficiency). This means that
you'll now be iterating over the actual values, not
over copies of the values. Modifications to the loop
variable can change the original values. To retain
Perl 4 semantics you need to assign your list
explicitly to a temporary array and then iterate over
that. For example, you might need to change
30/Jan/96 perl 5.002 with 7
PERLTRAP(1) User Contributed Perl Documentation PERLTRAP(1)
ffffoooorrrreeeeaaaacccchhhh $$$$vvvvaaaarrrr ((((ggggrrrreeeepppp ////xxxx////,,,, @@@@lllliiiisssstttt)))) {{{{ ............ }}}}
to
ffffoooorrrreeeeaaaacccchhhh $$$$vvvvaaaarrrr ((((mmmmyyyy @@@@ttttmmmmpppp ==== ggggrrrreeeepppp ////xxxx////,,,, @@@@lllliiiisssstttt)))) {{{{ ............ }}}}
Otherwise changing $$$$vvvvaaaarrrr will clobber the values of
@@@@lllliiiisssstttt. (This most often happens when you use $$$$____ for
the loop variable, and call subroutines in the loop
that don't properly localize $$$$____.)
+o Some error messages will be different.
+o Some bugs may have been inadvertently removed.
30/Jan/96 perl 5.002 with 8