| 1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index |
| 53 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
| 54 | .\" output yourself in some meaningful fashion. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 67 | .\" |
| 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
| 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. |
| 70 | . \" fudge factors for nroff and troff |
| 71 | .if n \{\ |
| 72 | . ds #H 0 |
| 73 | . ds #V .8m |
| 74 | . ds #F .3m |
| 75 | . ds #[ \f1 |
| 76 | . ds #] \fP |
| 77 | .\} |
| 78 | .if t \{\ |
| 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
| 80 | . ds #V .6m |
| 81 | . ds #F 0 |
| 82 | . ds #[ \& |
| 83 | . ds #] \& |
| 84 | .\} |
| 85 | . \" simple accents for nroff and troff |
| 86 | .if n \{\ |
| 87 | . ds ' \& |
| 88 | . ds ` \& |
| 89 | . ds ^ \& |
| 90 | . ds , \& |
| 91 | . ds ~ ~ |
| 92 | . ds / |
| 93 | .\} |
| 94 | .if t \{\ |
| 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
| 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' |
| 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' |
| 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' |
| 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' |
| 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' |
| 101 | .\} |
| 102 | . \" troff and (daisy-wheel) nroff accents |
| 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
| 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' |
| 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] |
| 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' |
| 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' |
| 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] |
| 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] |
| 110 | .ds ae a\h'-(\w'a'u*4/10)'e |
| 111 | .ds Ae A\h'-(\w'A'u*4/10)'E |
| 112 | . \" corrections for vroff |
| 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
| 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' |
| 115 | . \" for low resolution devices (crt and lpr) |
| 116 | .if \n(.H>23 .if \n(.V>19 \ |
| 117 | \{\ |
| 118 | . ds : e |
| 119 | . ds 8 ss |
| 120 | . ds o a |
| 121 | . ds d- d\h'-1'\(ga |
| 122 | . ds D- D\h'-1'\(hy |
| 123 | . ds th \o'bp' |
| 124 | . ds Th \o'LP' |
| 125 | . ds ae ae |
| 126 | . ds Ae AE |
| 127 | .\} |
| 128 | .rm #[ #] #H #V #F C |
| 129 | .\" ======================================================================== |
| 130 | .\" |
| 131 | .IX Title "PERLTRAP 1" |
| 132 | .TH PERLTRAP 1 "2006-01-07" "perl v5.8.8" "Perl Programmers Reference Guide" |
| 133 | .SH "NAME" |
| 134 | perltrap \- Perl traps for the unwary |
| 135 | .SH "DESCRIPTION" |
| 136 | .IX Header "DESCRIPTION" |
| 137 | The biggest trap of all is forgetting to \f(CW\*(C`use warnings\*(C'\fR or use the \fB\-w\fR |
| 138 | switch; see perllexwarn and perlrun. The second biggest trap is not |
| 139 | making your entire program runnable under \f(CW\*(C`use strict\*(C'\fR. The third biggest |
| 140 | trap is not reading the list of changes in this version of Perl; see |
| 141 | perldelta. |
| 142 | .Sh "Awk Traps" |
| 143 | .IX Subsection "Awk Traps" |
| 144 | Accustomed \fBawk\fR users should take special note of the following: |
| 145 | .IP "\(bu" 4 |
| 146 | A Perl program executes only once, not once for each input line. You can |
| 147 | do an implicit loop with \f(CW\*(C`\-n\*(C'\fR or \f(CW\*(C`\-p\*(C'\fR. |
| 148 | .IP "\(bu" 4 |
| 149 | The English module, loaded via |
| 150 | .Sp |
| 151 | .Vb 1 |
| 152 | \& use English; |
| 153 | .Ve |
| 154 | .Sp |
| 155 | allows you to refer to special variables (like \f(CW$/\fR) with names (like |
| 156 | \&\f(CW$RS\fR), as though they were in \fBawk\fR; see perlvar for details. |
| 157 | .IP "\(bu" 4 |
| 158 | Semicolons are required after all simple statements in Perl (except |
| 159 | at the end of a block). Newline is not a statement delimiter. |
| 160 | .IP "\(bu" 4 |
| 161 | Curly brackets are required on \f(CW\*(C`if\*(C'\fRs and \f(CW\*(C`while\*(C'\fRs. |
| 162 | .IP "\(bu" 4 |
| 163 | Variables begin with \*(L"$\*(R", \*(L"@\*(R" or \*(L"%\*(R" in Perl. |
| 164 | .IP "\(bu" 4 |
| 165 | Arrays index from 0. Likewise string positions in \fIsubstr()\fR and |
| 166 | \&\fIindex()\fR. |
| 167 | .IP "\(bu" 4 |
| 168 | You have to decide whether your array has numeric or string indices. |
| 169 | .IP "\(bu" 4 |
| 170 | Hash values do not spring into existence upon mere reference. |
| 171 | .IP "\(bu" 4 |
| 172 | You have to decide whether you want to use string or numeric |
| 173 | comparisons. |
| 174 | .IP "\(bu" 4 |
| 175 | Reading an input line does not split it for you. You get to split it |
| 176 | to an array yourself. And the \fIsplit()\fR operator has different |
| 177 | arguments than \fBawk\fR's. |
| 178 | .IP "\(bu" 4 |
| 179 | The current input line is normally in \f(CW$_\fR, not \f(CW$0\fR. It generally does |
| 180 | not have the newline stripped. ($0 is the name of the program |
| 181 | executed.) See perlvar. |
| 182 | .IP "\(bu" 4 |
| 183 | $<\fIdigit\fR> does not refer to fields\*(--it refers to substrings matched |
| 184 | by the last match pattern. |
| 185 | .IP "\(bu" 4 |
| 186 | The \fIprint()\fR statement does not add field and record separators unless |
| 187 | you set \f(CW$,\fR and \f(CW\*(C`$\e\*(C'\fR. You can set \f(CW$OFS\fR and \f(CW$ORS\fR if you're using |
| 188 | the English module. |
| 189 | .IP "\(bu" 4 |
| 190 | You must open your files before you print to them. |
| 191 | .IP "\(bu" 4 |
| 192 | The range operator is \*(L"..\*(R", not comma. The comma operator works as in |
| 193 | C. |
| 194 | .IP "\(bu" 4 |
| 195 | The match operator is \*(L"=~\*(R", not \*(L"~\*(R". (\*(L"~\*(R" is the one's complement |
| 196 | operator, as in C.) |
| 197 | .IP "\(bu" 4 |
| 198 | The exponentiation operator is \*(L"**\*(R", not \*(L"^\*(R". \*(L"^\*(R" is the \s-1XOR\s0 |
| 199 | operator, as in C. (You know, one could get the feeling that \fBawk\fR is |
| 200 | basically incompatible with C.) |
| 201 | .IP "\(bu" 4 |
| 202 | The concatenation operator is \*(L".\*(R", not the null string. (Using the |
| 203 | null string would render \f(CW\*(C`/pat/ /pat/\*(C'\fR unparsable, because the third slash |
| 204 | would be interpreted as a division operator\*(--the tokenizer is in fact |
| 205 | slightly context sensitive for operators like \*(L"/\*(R", \*(L"?\*(R", and \*(L">\*(R". |
| 206 | And in fact, \*(L".\*(R" itself can be the beginning of a number.) |
| 207 | .IP "\(bu" 4 |
| 208 | The \f(CW\*(C`next\*(C'\fR, \f(CW\*(C`exit\*(C'\fR, and \f(CW\*(C`continue\*(C'\fR keywords work differently. |
| 209 | .IP "\(bu" 4 |
| 210 | The following variables work differently: |
| 211 | .Sp |
| 212 | .Vb 15 |
| 213 | \& Awk Perl |
| 214 | \& ARGC scalar @ARGV (compare with $#ARGV) |
| 215 | \& ARGV[0] $0 |
| 216 | \& FILENAME $ARGV |
| 217 | \& FNR $. - something |
| 218 | \& FS (whatever you like) |
| 219 | \& NF $#Fld, or some such |
| 220 | \& NR $. |
| 221 | \& OFMT $# |
| 222 | \& OFS $, |
| 223 | \& ORS $\e |
| 224 | \& RLENGTH length($&) |
| 225 | \& RS $/ |
| 226 | \& RSTART length($`) |
| 227 | \& SUBSEP $; |
| 228 | .Ve |
| 229 | .IP "\(bu" 4 |
| 230 | You cannot set \f(CW$RS\fR to a pattern, only a string. |
| 231 | .IP "\(bu" 4 |
| 232 | When in doubt, run the \fBawk\fR construct through \fBa2p\fR and see what it |
| 233 | gives you. |
| 234 | .Sh "C/\*(C+ Traps" |
| 235 | .IX Subsection "C/ Traps" |
| 236 | Cerebral C and \*(C+ programmers should take note of the following: |
| 237 | .IP "\(bu" 4 |
| 238 | Curly brackets are required on \f(CW\*(C`if\*(C'\fR's and \f(CW\*(C`while\*(C'\fR's. |
| 239 | .IP "\(bu" 4 |
| 240 | You must use \f(CW\*(C`elsif\*(C'\fR rather than \f(CW\*(C`else if\*(C'\fR. |
| 241 | .IP "\(bu" 4 |
| 242 | The \f(CW\*(C`break\*(C'\fR and \f(CW\*(C`continue\*(C'\fR keywords from C become in Perl \f(CW\*(C`last\*(C'\fR |
| 243 | and \f(CW\*(C`next\*(C'\fR, respectively. Unlike in C, these do \fInot\fR work within a |
| 244 | \&\f(CW\*(C`do { } while\*(C'\fR construct. See \*(L"Loop Control\*(R" in perlsyn. |
| 245 | .IP "\(bu" 4 |
| 246 | There's no switch statement. (But it's easy to build one on the fly, |
| 247 | see \*(L"Basic BLOCKs and Switch Statements\*(R" in perlsyn) |
| 248 | .IP "\(bu" 4 |
| 249 | Variables begin with \*(L"$\*(R", \*(L"@\*(R" or \*(L"%\*(R" in Perl. |
| 250 | .IP "\(bu" 4 |
| 251 | Comments begin with \*(L"#\*(R", not \*(L"/*\*(R" or \*(L"//\*(R". Perl may interpret C/\*(C+ |
| 252 | comments as division operators, unterminated regular expressions or |
| 253 | the defined-or operator. |
| 254 | .IP "\(bu" 4 |
| 255 | You can't take the address of anything, although a similar operator |
| 256 | in Perl is the backslash, which creates a reference. |
| 257 | .IP "\(bu" 4 |
| 258 | \&\f(CW\*(C`ARGV\*(C'\fR must be capitalized. \f(CW$ARGV[0]\fR is C's \f(CW\*(C`argv[1]\*(C'\fR, and \f(CW\*(C`argv[0]\*(C'\fR |
| 259 | ends up in \f(CW$0\fR. |
| 260 | .IP "\(bu" 4 |
| 261 | System calls such as \fIlink()\fR, \fIunlink()\fR, \fIrename()\fR, etc. return nonzero for |
| 262 | success, not 0. (\fIsystem()\fR, however, returns zero for success.) |
| 263 | .IP "\(bu" 4 |
| 264 | Signal handlers deal with signal names, not numbers. Use \f(CW\*(C`kill \-l\*(C'\fR |
| 265 | to find their names on your system. |
| 266 | .Sh "Sed Traps" |
| 267 | .IX Subsection "Sed Traps" |
| 268 | Seasoned \fBsed\fR programmers should take note of the following: |
| 269 | .IP "\(bu" 4 |
| 270 | A Perl program executes only once, not once for each input line. You can |
| 271 | do an implicit loop with \f(CW\*(C`\-n\*(C'\fR or \f(CW\*(C`\-p\*(C'\fR. |
| 272 | .IP "\(bu" 4 |
| 273 | Backreferences in substitutions use \*(L"$\*(R" rather than \*(L"\e\*(R". |
| 274 | .IP "\(bu" 4 |
| 275 | The pattern matching metacharacters \*(L"(\*(R", \*(L")\*(R", and \*(L"|\*(R" do not have backslashes |
| 276 | in front. |
| 277 | .IP "\(bu" 4 |
| 278 | The range operator is \f(CW\*(C`...\*(C'\fR, rather than comma. |
| 279 | .Sh "Shell Traps" |
| 280 | .IX Subsection "Shell Traps" |
| 281 | Sharp shell programmers should take note of the following: |
| 282 | .IP "\(bu" 4 |
| 283 | The backtick operator does variable interpolation without regard to |
| 284 | the presence of single quotes in the command. |
| 285 | .IP "\(bu" 4 |
| 286 | The backtick operator does no translation of the return value, unlike \fBcsh\fR. |
| 287 | .IP "\(bu" 4 |
| 288 | Shells (especially \fBcsh\fR) do several levels of substitution on each |
| 289 | command line. Perl does substitution in only certain constructs |
| 290 | such as double quotes, backticks, angle brackets, and search patterns. |
| 291 | .IP "\(bu" 4 |
| 292 | Shells interpret scripts a little bit at a time. Perl compiles the |
| 293 | entire program before executing it (except for \f(CW\*(C`BEGIN\*(C'\fR blocks, which |
| 294 | execute at compile time). |
| 295 | .IP "\(bu" 4 |
| 296 | The arguments are available via \f(CW@ARGV\fR, not \f(CW$1\fR, \f(CW$2\fR, etc. |
| 297 | .IP "\(bu" 4 |
| 298 | The environment is not automatically made available as separate scalar |
| 299 | variables. |
| 300 | .IP "\(bu" 4 |
| 301 | The shell's \f(CW\*(C`test\*(C'\fR uses \*(L"=\*(R", \*(L"!=\*(R", \*(L"<\*(R" etc for string comparisons and \*(L"\-eq\*(R", |
| 302 | \&\*(L"\-ne\*(R", \*(L"\-lt\*(R" etc for numeric comparisons. This is the reverse of Perl, which |
| 303 | uses \f(CW\*(C`eq\*(C'\fR, \f(CW\*(C`ne\*(C'\fR, \f(CW\*(C`lt\*(C'\fR for string comparisons, and \f(CW\*(C`==\*(C'\fR, \f(CW\*(C`!=\*(C'\fR \f(CW\*(C`<\*(C'\fR etc |
| 304 | for numeric comparisons. |
| 305 | .Sh "Perl Traps" |
| 306 | .IX Subsection "Perl Traps" |
| 307 | Practicing Perl Programmers should take note of the following: |
| 308 | .IP "\(bu" 4 |
| 309 | Remember that many operations behave differently in a list |
| 310 | context than they do in a scalar one. See perldata for details. |
| 311 | .IP "\(bu" 4 |
| 312 | Avoid barewords if you can, especially all lowercase ones. |
| 313 | You can't tell by just looking at it whether a bareword is |
| 314 | a function or a string. By using quotes on strings and |
| 315 | parentheses on function calls, you won't ever get them confused. |
| 316 | .IP "\(bu" 4 |
| 317 | You cannot discern from mere inspection which builtins |
| 318 | are unary operators (like \fIchop()\fR and \fIchdir()\fR) |
| 319 | and which are list operators (like \fIprint()\fR and \fIunlink()\fR). |
| 320 | (Unless prototyped, user-defined subroutines can \fBonly\fR be list |
| 321 | operators, never unary ones.) See perlop and perlsub. |
| 322 | .IP "\(bu" 4 |
| 323 | People have a hard time remembering that some functions |
| 324 | default to \f(CW$_\fR, or \f(CW@ARGV\fR, or whatever, but that others which |
| 325 | you might expect to do not. |
| 326 | .IP "\(bu" 4 |
| 327 | The <\s-1FH\s0> construct is not the name of the filehandle, it is a readline |
| 328 | operation on that handle. The data read is assigned to \f(CW$_\fR only if the |
| 329 | file read is the sole condition in a while loop: |
| 330 | .Sp |
| 331 | .Vb 3 |
| 332 | \& while (<FH>) { } |
| 333 | \& while (defined($_ = <FH>)) { }.. |
| 334 | \& <FH>; # data discarded! |
| 335 | .Ve |
| 336 | .IP "\(bu" 4 |
| 337 | Remember not to use \f(CW\*(C`=\*(C'\fR when you need \f(CW\*(C`=~\*(C'\fR; |
| 338 | these two constructs are quite different: |
| 339 | .Sp |
| 340 | .Vb 2 |
| 341 | \& $x = /foo/; |
| 342 | \& $x =~ /foo/; |
| 343 | .Ve |
| 344 | .IP "\(bu" 4 |
| 345 | The \f(CW\*(C`do {}\*(C'\fR construct isn't a real loop that you can use |
| 346 | loop control on. |
| 347 | .IP "\(bu" 4 |
| 348 | Use \f(CW\*(C`my()\*(C'\fR for local variables whenever you can get away with |
| 349 | it (but see perlform for where you can't). |
| 350 | Using \f(CW\*(C`local()\*(C'\fR actually gives a local value to a global |
| 351 | variable, which leaves you open to unforeseen side-effects |
| 352 | of dynamic scoping. |
| 353 | .IP "\(bu" 4 |
| 354 | If you localize an exported variable in a module, its exported value will |
| 355 | not change. The local name becomes an alias to a new value but the |
| 356 | external name is still an alias for the original. |
| 357 | .Sh "Perl4 to Perl5 Traps" |
| 358 | .IX Subsection "Perl4 to Perl5 Traps" |
| 359 | Practicing Perl4 Programmers should take note of the following |
| 360 | Perl4\-to\-Perl5 specific traps. |
| 361 | .PP |
| 362 | They're crudely ordered according to the following list: |
| 363 | .IP "Discontinuance, Deprecation, and BugFix traps" 4 |
| 364 | .IX Item "Discontinuance, Deprecation, and BugFix traps" |
| 365 | Anything that's been fixed as a perl4 bug, removed as a perl4 feature |
| 366 | or deprecated as a perl4 feature with the intent to encourage usage of |
| 367 | some other perl5 feature. |
| 368 | .IP "Parsing Traps" 4 |
| 369 | .IX Item "Parsing Traps" |
| 370 | Traps that appear to stem from the new parser. |
| 371 | .IP "Numerical Traps" 4 |
| 372 | .IX Item "Numerical Traps" |
| 373 | Traps having to do with numerical or mathematical operators. |
| 374 | .IP "General data type traps" 4 |
| 375 | .IX Item "General data type traps" |
| 376 | Traps involving perl standard data types. |
| 377 | .IP "Context Traps \- scalar, list contexts" 4 |
| 378 | .IX Item "Context Traps - scalar, list contexts" |
| 379 | Traps related to context within lists, scalar statements/declarations. |
| 380 | .IP "Precedence Traps" 4 |
| 381 | .IX Item "Precedence Traps" |
| 382 | Traps related to the precedence of parsing, evaluation, and execution of |
| 383 | code. |
| 384 | .IP "General Regular Expression Traps using s///, etc." 4 |
| 385 | .IX Item "General Regular Expression Traps using s///, etc." |
| 386 | Traps related to the use of pattern matching. |
| 387 | .IP "Subroutine, Signal, Sorting Traps" 4 |
| 388 | .IX Item "Subroutine, Signal, Sorting Traps" |
| 389 | Traps related to the use of signals and signal handlers, general subroutines, |
| 390 | and sorting, along with sorting subroutines. |
| 391 | .IP "\s-1OS\s0 Traps" 4 |
| 392 | .IX Item "OS Traps" |
| 393 | OS-specific traps. |
| 394 | .IP "\s-1DBM\s0 Traps" 4 |
| 395 | .IX Item "DBM Traps" |
| 396 | Traps specific to the use of \f(CW\*(C`dbmopen()\*(C'\fR, and specific dbm implementations. |
| 397 | .IP "Unclassified Traps" 4 |
| 398 | .IX Item "Unclassified Traps" |
| 399 | Everything else. |
| 400 | .PP |
| 401 | If you find an example of a conversion trap that is not listed here, |
| 402 | please submit it to <\fIperlbug@perl.org\fR> for inclusion. |
| 403 | Also note that at least some of these can be caught with the |
| 404 | \&\f(CW\*(C`use warnings\*(C'\fR pragma or the \fB\-w\fR switch. |
| 405 | .Sh "Discontinuance, Deprecation, and BugFix traps" |
| 406 | .IX Subsection "Discontinuance, Deprecation, and BugFix traps" |
| 407 | Anything that has been discontinued, deprecated, or fixed as |
| 408 | a bug from perl4. |
| 409 | .ie n .IP "* Symbols starting with ""_"" no longer forced into main" 4 |
| 410 | .el .IP "* Symbols starting with ``_'' no longer forced into main" 4 |
| 411 | .IX Item "Symbols starting with _ no longer forced into main" |
| 412 | Symbols starting with \*(L"_\*(R" are no longer forced into package main, except |
| 413 | for \f(CW$_\fR itself (and \f(CW@_\fR, etc.). |
| 414 | .Sp |
| 415 | .Vb 2 |
| 416 | \& package test; |
| 417 | \& $_legacy = 1; |
| 418 | .Ve |
| 419 | .Sp |
| 420 | .Vb 2 |
| 421 | \& package main; |
| 422 | \& print "\e$_legacy is ",$_legacy,"\en"; |
| 423 | .Ve |
| 424 | .Sp |
| 425 | .Vb 2 |
| 426 | \& # perl4 prints: $_legacy is 1 |
| 427 | \& # perl5 prints: $_legacy is |
| 428 | .Ve |
| 429 | .IP "* Double-colon valid package separator in variable name" 4 |
| 430 | .IX Item "Double-colon valid package separator in variable name" |
| 431 | Double-colon is now a valid package separator in a variable name. Thus these |
| 432 | behave differently in perl4 vs. perl5, because the packages don't exist. |
| 433 | .Sp |
| 434 | .Vb 3 |
| 435 | \& $a=1;$b=2;$c=3;$var=4; |
| 436 | \& print "$a::$b::$c "; |
| 437 | \& print "$var::abc::xyz\en"; |
| 438 | .Ve |
| 439 | .Sp |
| 440 | .Vb 2 |
| 441 | \& # perl4 prints: 1::2::3 4::abc::xyz |
| 442 | \& # perl5 prints: 3 |
| 443 | .Ve |
| 444 | .Sp |
| 445 | Given that \f(CW\*(C`::\*(C'\fR is now the preferred package delimiter, it is debatable |
| 446 | whether this should be classed as a bug or not. |
| 447 | (The older package delimiter, ' ,is used here) |
| 448 | .Sp |
| 449 | .Vb 2 |
| 450 | \& $x = 10; |
| 451 | \& print "x=${'x}\en"; |
| 452 | .Ve |
| 453 | .Sp |
| 454 | .Vb 2 |
| 455 | \& # perl4 prints: x=10 |
| 456 | \& # perl5 prints: Can't find string terminator "'" anywhere before EOF |
| 457 | .Ve |
| 458 | .Sp |
| 459 | You can avoid this problem, and remain compatible with perl4, if you |
| 460 | always explicitly include the package name: |
| 461 | .Sp |
| 462 | .Vb 2 |
| 463 | \& $x = 10; |
| 464 | \& print "x=${main'x}\en"; |
| 465 | .Ve |
| 466 | .Sp |
| 467 | Also see precedence traps, for parsing \f(CW$:\fR. |
| 468 | .ie n .IP "* 2nd and 3rd args to ""splice()"" are now in scalar context" 4 |
| 469 | .el .IP "* 2nd and 3rd args to \f(CWsplice()\fR are now in scalar context" 4 |
| 470 | .IX Item "2nd and 3rd args to splice() are now in scalar context" |
| 471 | The second and third arguments of \f(CW\*(C`splice()\*(C'\fR are now evaluated in scalar |
| 472 | context (as the Camel says) rather than list context. |
| 473 | .Sp |
| 474 | .Vb 5 |
| 475 | \& sub sub1{return(0,2) } # return a 2-element list |
| 476 | \& sub sub2{ return(1,2,3)} # return a 3-element list |
| 477 | \& @a1 = ("a","b","c","d","e"); |
| 478 | \& @a2 = splice(@a1,&sub1,&sub2); |
| 479 | \& print join(' ',@a2),"\en"; |
| 480 | .Ve |
| 481 | .Sp |
| 482 | .Vb 2 |
| 483 | \& # perl4 prints: a b |
| 484 | \& # perl5 prints: c d e |
| 485 | .Ve |
| 486 | .ie n .IP "* Can't do ""goto"" into a block that is optimized away" 4 |
| 487 | .el .IP "* Can't do \f(CWgoto\fR into a block that is optimized away" 4 |
| 488 | .IX Item "Can't do goto into a block that is optimized away" |
| 489 | You can't do a \f(CW\*(C`goto\*(C'\fR into a block that is optimized away. Darn. |
| 490 | .Sp |
| 491 | .Vb 1 |
| 492 | \& goto marker1; |
| 493 | .Ve |
| 494 | .Sp |
| 495 | .Vb 4 |
| 496 | \& for(1){ |
| 497 | \& marker1: |
| 498 | \& print "Here I is!\en"; |
| 499 | \& } |
| 500 | .Ve |
| 501 | .Sp |
| 502 | .Vb 2 |
| 503 | \& # perl4 prints: Here I is! |
| 504 | \& # perl5 errors: Can't "goto" into the middle of a foreach loop |
| 505 | .Ve |
| 506 | .IP "* Can't use whitespace as variable name or quote delimiter" 4 |
| 507 | .IX Item "Can't use whitespace as variable name or quote delimiter" |
| 508 | It is no longer syntactically legal to use whitespace as the name |
| 509 | of a variable, or as a delimiter for any kind of quote construct. |
| 510 | Double darn. |
| 511 | .Sp |
| 512 | .Vb 3 |
| 513 | \& $a = ("foo bar"); |
| 514 | \& $b = q baz; |
| 515 | \& print "a is $a, b is $b\en"; |
| 516 | .Ve |
| 517 | .Sp |
| 518 | .Vb 2 |
| 519 | \& # perl4 prints: a is foo bar, b is baz |
| 520 | \& # perl5 errors: Bareword found where operator expected |
| 521 | .Ve |
| 522 | .ie n .IP "* ""while/if BLOCK BLOCK"" gone" 4 |
| 523 | .el .IP "* \f(CWwhile/if BLOCK BLOCK\fR gone" 4 |
| 524 | .IX Item "while/if BLOCK BLOCK gone" |
| 525 | The archaic while/if \s-1BLOCK\s0 \s-1BLOCK\s0 syntax is no longer supported. |
| 526 | .Sp |
| 527 | .Vb 6 |
| 528 | \& if { 1 } { |
| 529 | \& print "True!"; |
| 530 | \& } |
| 531 | \& else { |
| 532 | \& print "False!"; |
| 533 | \& } |
| 534 | .Ve |
| 535 | .Sp |
| 536 | .Vb 2 |
| 537 | \& # perl4 prints: True! |
| 538 | \& # perl5 errors: syntax error at test.pl line 1, near "if {" |
| 539 | .Ve |
| 540 | .ie n .IP "* ""**"" binds tighter than unary minus" 4 |
| 541 | .el .IP "* \f(CW**\fR binds tighter than unary minus" 4 |
| 542 | .IX Item "** binds tighter than unary minus" |
| 543 | The \f(CW\*(C`**\*(C'\fR operator now binds more tightly than unary minus. |
| 544 | It was documented to work this way before, but didn't. |
| 545 | .Sp |
| 546 | .Vb 1 |
| 547 | \& print -4**2,"\en"; |
| 548 | .Ve |
| 549 | .Sp |
| 550 | .Vb 2 |
| 551 | \& # perl4 prints: 16 |
| 552 | \& # perl5 prints: -16 |
| 553 | .Ve |
| 554 | .ie n .IP "* ""foreach"" changed when iterating over a list" 4 |
| 555 | .el .IP "* \f(CWforeach\fR changed when iterating over a list" 4 |
| 556 | .IX Item "foreach changed when iterating over a list" |
| 557 | The meaning of \f(CW\*(C`foreach{}\*(C'\fR has changed slightly when it is iterating over a |
| 558 | list which is not an array. This used to assign the list to a |
| 559 | temporary array, but no longer does so (for efficiency). This means |
| 560 | that you'll now be iterating over the actual values, not over copies of |
| 561 | the values. Modifications to the loop variable can change the original |
| 562 | values. |
| 563 | .Sp |
| 564 | .Vb 5 |
| 565 | \& @list = ('ab','abc','bcd','def'); |
| 566 | \& foreach $var (grep(/ab/,@list)){ |
| 567 | \& $var = 1; |
| 568 | \& } |
| 569 | \& print (join(':',@list)); |
| 570 | .Ve |
| 571 | .Sp |
| 572 | .Vb 2 |
| 573 | \& # perl4 prints: ab:abc:bcd:def |
| 574 | \& # perl5 prints: 1:1:bcd:def |
| 575 | .Ve |
| 576 | .Sp |
| 577 | To retain Perl4 semantics you need to assign your list |
| 578 | explicitly to a temporary array and then iterate over that. For |
| 579 | example, you might need to change |
| 580 | .Sp |
| 581 | .Vb 1 |
| 582 | \& foreach $var (grep(/ab/,@list)){ |
| 583 | .Ve |
| 584 | .Sp |
| 585 | to |
| 586 | .Sp |
| 587 | .Vb 1 |
| 588 | \& foreach $var (@tmp = grep(/ab/,@list)){ |
| 589 | .Ve |
| 590 | .Sp |
| 591 | Otherwise changing \f(CW$var\fR will clobber the values of \f(CW@list\fR. (This most often |
| 592 | happens when you use \f(CW$_\fR for the loop variable, and call subroutines in |
| 593 | the loop that don't properly localize \f(CW$_\fR.) |
| 594 | .ie n .IP "* ""split"" with no args behavior changed" 4 |
| 595 | .el .IP "* \f(CWsplit\fR with no args behavior changed" 4 |
| 596 | .IX Item "split with no args behavior changed" |
| 597 | \&\f(CW\*(C`split\*(C'\fR with no arguments now behaves like \f(CW\*(C`split ' '\*(C'\fR (which doesn't |
| 598 | return an initial null field if \f(CW$_\fR starts with whitespace), it used to |
| 599 | behave like \f(CW\*(C`split /\es+/\*(C'\fR (which does). |
| 600 | .Sp |
| 601 | .Vb 2 |
| 602 | \& $_ = ' hi mom'; |
| 603 | \& print join(':', split); |
| 604 | .Ve |
| 605 | .Sp |
| 606 | .Vb 2 |
| 607 | \& # perl4 prints: :hi:mom |
| 608 | \& # perl5 prints: hi:mom |
| 609 | .Ve |
| 610 | .IP "* \fB\-e\fR behavior fixed" 4 |
| 611 | .IX Item "-e behavior fixed" |
| 612 | Perl 4 would ignore any text which was attached to an \fB\-e\fR switch, |
| 613 | always taking the code snippet from the following arg. Additionally, it |
| 614 | would silently accept an \fB\-e\fR switch without a following arg. Both of |
| 615 | these behaviors have been fixed. |
| 616 | .Sp |
| 617 | .Vb 1 |
| 618 | \& perl -e'print "attached to -e"' 'print "separate arg"' |
| 619 | .Ve |
| 620 | .Sp |
| 621 | .Vb 2 |
| 622 | \& # perl4 prints: separate arg |
| 623 | \& # perl5 prints: attached to -e |
| 624 | .Ve |
| 625 | .Sp |
| 626 | .Vb 1 |
| 627 | \& perl -e |
| 628 | .Ve |
| 629 | .Sp |
| 630 | .Vb 2 |
| 631 | \& # perl4 prints: |
| 632 | \& # perl5 dies: No code specified for -e. |
| 633 | .Ve |
| 634 | .ie n .IP "* ""push"" returns number of elements in resulting list" 4 |
| 635 | .el .IP "* \f(CWpush\fR returns number of elements in resulting list" 4 |
| 636 | .IX Item "push returns number of elements in resulting list" |
| 637 | In Perl 4 the return value of \f(CW\*(C`push\*(C'\fR was undocumented, but it was |
| 638 | actually the last value being pushed onto the target list. In Perl 5 |
| 639 | the return value of \f(CW\*(C`push\*(C'\fR is documented, but has changed, it is the |
| 640 | number of elements in the resulting list. |
| 641 | .Sp |
| 642 | .Vb 2 |
| 643 | \& @x = ('existing'); |
| 644 | \& print push(@x, 'first new', 'second new'); |
| 645 | .Ve |
| 646 | .Sp |
| 647 | .Vb 2 |
| 648 | \& # perl4 prints: second new |
| 649 | \& # perl5 prints: 3 |
| 650 | .Ve |
| 651 | .IP "* Some error messages differ" 4 |
| 652 | .IX Item "Some error messages differ" |
| 653 | Some error messages will be different. |
| 654 | .ie n .IP "* ""split()"" honors subroutine args" 4 |
| 655 | .el .IP "* \f(CWsplit()\fR honors subroutine args" 4 |
| 656 | .IX Item "split() honors subroutine args" |
| 657 | In Perl 4, if in list context the delimiters to the first argument of |
| 658 | \&\f(CW\*(C`split()\*(C'\fR were \f(CW\*(C`??\*(C'\fR, the result would be placed in \f(CW@_\fR as well as |
| 659 | being returned. Perl 5 has more respect for your subroutine arguments. |
| 660 | .IP "* Bugs removed" 4 |
| 661 | .IX Item "Bugs removed" |
| 662 | Some bugs may have been inadvertently removed. :\-) |
| 663 | .Sh "Parsing Traps" |
| 664 | .IX Subsection "Parsing Traps" |
| 665 | Perl4\-to\-Perl5 traps from having to do with parsing. |
| 666 | .IP "* Space between . and = triggers syntax error" 4 |
| 667 | .IX Item "Space between . and = triggers syntax error" |
| 668 | Note the space between . and = |
| 669 | .Sp |
| 670 | .Vb 2 |
| 671 | \& $string . = "more string"; |
| 672 | \& print $string; |
| 673 | .Ve |
| 674 | .Sp |
| 675 | .Vb 2 |
| 676 | \& # perl4 prints: more string |
| 677 | \& # perl5 prints: syntax error at - line 1, near ". =" |
| 678 | .Ve |
| 679 | .IP "* Better parsing in perl 5" 4 |
| 680 | .IX Item "Better parsing in perl 5" |
| 681 | Better parsing in perl 5 |
| 682 | .Sp |
| 683 | .Vb 3 |
| 684 | \& sub foo {} |
| 685 | \& &foo |
| 686 | \& print("hello, world\en"); |
| 687 | .Ve |
| 688 | .Sp |
| 689 | .Vb 2 |
| 690 | \& # perl4 prints: hello, world |
| 691 | \& # perl5 prints: syntax error |
| 692 | .Ve |
| 693 | .IP "* Function parsing" 4 |
| 694 | .IX Item "Function parsing" |
| 695 | \&\*(L"if it looks like a function, it is a function\*(R" rule. |
| 696 | .Sp |
| 697 | .Vb 2 |
| 698 | \& print |
| 699 | \& ($foo == 1) ? "is one\en" : "is zero\en"; |
| 700 | .Ve |
| 701 | .Sp |
| 702 | .Vb 2 |
| 703 | \& # perl4 prints: is zero |
| 704 | \& # perl5 warns: "Useless use of a constant in void context" if using -w |
| 705 | .Ve |
| 706 | .ie n .IP "* String interpolation of $#array differs" 4 |
| 707 | .el .IP "* String interpolation of \f(CW$#array\fR differs" 4 |
| 708 | .IX Item "String interpolation of $#array differs" |
| 709 | String interpolation of the \f(CW$#array\fR construct differs when braces |
| 710 | are to used around the name. |
| 711 | .Sp |
| 712 | .Vb 2 |
| 713 | \& @a = (1..3); |
| 714 | \& print "${#a}"; |
| 715 | .Ve |
| 716 | .Sp |
| 717 | .Vb 2 |
| 718 | \& # perl4 prints: 2 |
| 719 | \& # perl5 fails with syntax error |
| 720 | .Ve |
| 721 | .Sp |
| 722 | .Vb 2 |
| 723 | \& @ = (1..3); |
| 724 | \& print "$#{a}"; |
| 725 | .Ve |
| 726 | .Sp |
| 727 | .Vb 2 |
| 728 | \& # perl4 prints: {a} |
| 729 | \& # perl5 prints: 2 |
| 730 | .Ve |
| 731 | .ie n .IP "* Perl guesses on ""map""\fR, \f(CW""grep""\fR followed by \f(CW""{"" if it starts \s-1BLOCK\s0 or hash ref" 4 |
| 732 | .el .IP "* Perl guesses on \f(CWmap\fR, \f(CWgrep\fR followed by \f(CW{\fR if it starts \s-1BLOCK\s0 or hash ref" 4 |
| 733 | .IX Item "Perl guesses on map, grep followed by { if it starts BLOCK or hash ref" |
| 734 | When perl sees \f(CW\*(C`map {\*(C'\fR (or \f(CW\*(C`grep {\*(C'\fR), it has to guess whether the \f(CW\*(C`{\*(C'\fR |
| 735 | starts a \s-1BLOCK\s0 or a hash reference. If it guesses wrong, it will report |
| 736 | a syntax error near the \f(CW\*(C`}\*(C'\fR and the missing (or unexpected) comma. |
| 737 | .Sp |
| 738 | Use unary \f(CW\*(C`+\*(C'\fR before \f(CW\*(C`{\*(C'\fR on a hash reference, and unary \f(CW\*(C`+\*(C'\fR applied |
| 739 | to the first thing in a \s-1BLOCK\s0 (after \f(CW\*(C`{\*(C'\fR), for perl to guess right all |
| 740 | the time. (See \*(L"map\*(R" in perlfunc.) |
| 741 | .Sh "Numerical Traps" |
| 742 | .IX Subsection "Numerical Traps" |
| 743 | Perl4\-to\-Perl5 traps having to do with numerical operators, |
| 744 | operands, or output from same. |
| 745 | .IP "* Formatted output and significant digits" 5 |
| 746 | .IX Item "Formatted output and significant digits" |
| 747 | Formatted output and significant digits. In general, Perl 5 |
| 748 | tries to be more precise. For example, on a Solaris Sparc: |
| 749 | .Sp |
| 750 | .Vb 2 |
| 751 | \& print 7.373504 - 0, "\en"; |
| 752 | \& printf "%20.18f\en", 7.373504 - 0; |
| 753 | .Ve |
| 754 | .Sp |
| 755 | .Vb 3 |
| 756 | \& # Perl4 prints: |
| 757 | \& 7.3750399999999996141 |
| 758 | \& 7.375039999999999614 |
| 759 | .Ve |
| 760 | .Sp |
| 761 | .Vb 3 |
| 762 | \& # Perl5 prints: |
| 763 | \& 7.373504 |
| 764 | \& 7.375039999999999614 |
| 765 | .Ve |
| 766 | .Sp |
| 767 | Notice how the first result looks better in Perl 5. |
| 768 | .Sp |
| 769 | Your results may vary, since your floating point formatting routines |
| 770 | and even floating point format may be slightly different. |
| 771 | .IP "* Auto-increment operator over signed int limit deleted" 5 |
| 772 | .IX Item "Auto-increment operator over signed int limit deleted" |
| 773 | This specific item has been deleted. It demonstrated how the auto-increment |
| 774 | operator would not catch when a number went over the signed int limit. Fixed |
| 775 | in version 5.003_04. But always be wary when using large integers. |
| 776 | If in doubt: |
| 777 | .Sp |
| 778 | .Vb 1 |
| 779 | \& use Math::BigInt; |
| 780 | .Ve |
| 781 | .IP "* Assignment of return values from numeric equality tests doesn't work" 5 |
| 782 | .IX Item "Assignment of return values from numeric equality tests doesn't work" |
| 783 | Assignment of return values from numeric equality tests |
| 784 | does not work in perl5 when the test evaluates to false (0). |
| 785 | Logical tests now return a null, instead of 0 |
| 786 | .Sp |
| 787 | .Vb 2 |
| 788 | \& $p = ($test == 1); |
| 789 | \& print $p,"\en"; |
| 790 | .Ve |
| 791 | .Sp |
| 792 | .Vb 2 |
| 793 | \& # perl4 prints: 0 |
| 794 | \& # perl5 prints: |
| 795 | .Ve |
| 796 | .Sp |
| 797 | Also see \*(L"General Regular Expression Traps using s///, etc.\*(R" |
| 798 | for another example of this new feature... |
| 799 | .IP "* Bitwise string ops" 5 |
| 800 | .IX Item "Bitwise string ops" |
| 801 | When bitwise operators which can operate upon either numbers or |
| 802 | strings (\f(CW\*(C`& | ^ ~\*(C'\fR) are given only strings as arguments, perl4 would |
| 803 | treat the operands as bitstrings so long as the program contained a call |
| 804 | to the \f(CW\*(C`vec()\*(C'\fR function. perl5 treats the string operands as bitstrings. |
| 805 | (See \*(L"Bitwise String Operators\*(R" in perlop for more details.) |
| 806 | .Sp |
| 807 | .Vb 6 |
| 808 | \& $fred = "10"; |
| 809 | \& $barney = "12"; |
| 810 | \& $betty = $fred & $barney; |
| 811 | \& print "$betty\en"; |
| 812 | \& # Uncomment the next line to change perl4's behavior |
| 813 | \& # ($dummy) = vec("dummy", 0, 0); |
| 814 | .Ve |
| 815 | .Sp |
| 816 | .Vb 2 |
| 817 | \& # Perl4 prints: |
| 818 | \& 8 |
| 819 | .Ve |
| 820 | .Sp |
| 821 | .Vb 2 |
| 822 | \& # Perl5 prints: |
| 823 | \& 10 |
| 824 | .Ve |
| 825 | .Sp |
| 826 | .Vb 2 |
| 827 | \& # If vec() is used anywhere in the program, both print: |
| 828 | \& 10 |
| 829 | .Ve |
| 830 | .Sh "General data type traps" |
| 831 | .IX Subsection "General data type traps" |
| 832 | Perl4\-to\-Perl5 traps involving most data\-types, and their usage |
| 833 | within certain expressions and/or context. |
| 834 | .IP "* Negative array subscripts now count from the end of array" 5 |
| 835 | .IX Item "Negative array subscripts now count from the end of array" |
| 836 | Negative array subscripts now count from the end of the array. |
| 837 | .Sp |
| 838 | .Vb 2 |
| 839 | \& @a = (1, 2, 3, 4, 5); |
| 840 | \& print "The third element of the array is $a[3] also expressed as $a[-2] \en"; |
| 841 | .Ve |
| 842 | .Sp |
| 843 | .Vb 2 |
| 844 | \& # perl4 prints: The third element of the array is 4 also expressed as |
| 845 | \& # perl5 prints: The third element of the array is 4 also expressed as 4 |
| 846 | .Ve |
| 847 | .ie n .IP "* Setting $#array lower now discards array elements" 5 |
| 848 | .el .IP "* Setting \f(CW$#array\fR lower now discards array elements" 5 |
| 849 | .IX Item "Setting $#array lower now discards array elements" |
| 850 | Setting \f(CW$#array\fR lower now discards array elements, and makes them |
| 851 | impossible to recover. |
| 852 | .Sp |
| 853 | .Vb 6 |
| 854 | \& @a = (a,b,c,d,e); |
| 855 | \& print "Before: ",join('',@a); |
| 856 | \& $#a =1; |
| 857 | \& print ", After: ",join('',@a); |
| 858 | \& $#a =3; |
| 859 | \& print ", Recovered: ",join('',@a),"\en"; |
| 860 | .Ve |
| 861 | .Sp |
| 862 | .Vb 2 |
| 863 | \& # perl4 prints: Before: abcde, After: ab, Recovered: abcd |
| 864 | \& # perl5 prints: Before: abcde, After: ab, Recovered: ab |
| 865 | .Ve |
| 866 | .IP "* Hashes get defined before use" 5 |
| 867 | .IX Item "Hashes get defined before use" |
| 868 | Hashes get defined before use |
| 869 | .Sp |
| 870 | .Vb 4 |
| 871 | \& local($s,@a,%h); |
| 872 | \& die "scalar \e$s defined" if defined($s); |
| 873 | \& die "array \e@a defined" if defined(@a); |
| 874 | \& die "hash \e%h defined" if defined(%h); |
| 875 | .Ve |
| 876 | .Sp |
| 877 | .Vb 2 |
| 878 | \& # perl4 prints: |
| 879 | \& # perl5 dies: hash %h defined |
| 880 | .Ve |
| 881 | .Sp |
| 882 | Perl will now generate a warning when it sees defined(@a) and |
| 883 | defined(%h). |
| 884 | .IP "* Glob assignment from localized variable to variable" 5 |
| 885 | .IX Item "Glob assignment from localized variable to variable" |
| 886 | glob assignment from variable to variable will fail if the assigned |
| 887 | variable is localized subsequent to the assignment |
| 888 | .Sp |
| 889 | .Vb 4 |
| 890 | \& @a = ("This is Perl 4"); |
| 891 | \& *b = *a; |
| 892 | \& local(@a); |
| 893 | \& print @b,"\en"; |
| 894 | .Ve |
| 895 | .Sp |
| 896 | .Vb 2 |
| 897 | \& # perl4 prints: This is Perl 4 |
| 898 | \& # perl5 prints: |
| 899 | .Ve |
| 900 | .ie n .IP "* Assigning ""undef"" to glob" 5 |
| 901 | .el .IP "* Assigning \f(CWundef\fR to glob" 5 |
| 902 | .IX Item "Assigning undef to glob" |
| 903 | Assigning \f(CW\*(C`undef\*(C'\fR to a glob has no effect in Perl 5. In Perl 4 |
| 904 | it undefines the associated scalar (but may have other side effects |
| 905 | including SEGVs). Perl 5 will also warn if \f(CW\*(C`undef\*(C'\fR is assigned to a |
| 906 | typeglob. (Note that assigning \f(CW\*(C`undef\*(C'\fR to a typeglob is different |
| 907 | than calling the \f(CW\*(C`undef\*(C'\fR function on a typeglob (\f(CW\*(C`undef *foo\*(C'\fR), which |
| 908 | has quite a few effects. |
| 909 | .Sp |
| 910 | .Vb 3 |
| 911 | \& $foo = "bar"; |
| 912 | \& *foo = undef; |
| 913 | \& print $foo; |
| 914 | .Ve |
| 915 | .Sp |
| 916 | .Vb 4 |
| 917 | \& # perl4 prints: |
| 918 | \& # perl4 warns: "Use of uninitialized variable" if using -w |
| 919 | \& # perl5 prints: bar |
| 920 | \& # perl5 warns: "Undefined value assigned to typeglob" if using -w |
| 921 | .Ve |
| 922 | .IP "* Changes in unary negation (of strings)" 5 |
| 923 | .IX Item "Changes in unary negation (of strings)" |
| 924 | Changes in unary negation (of strings) |
| 925 | This change effects both the return value and what it |
| 926 | does to auto(magic)increment. |
| 927 | .Sp |
| 928 | .Vb 4 |
| 929 | \& $x = "aaa"; |
| 930 | \& print ++$x," : "; |
| 931 | \& print -$x," : "; |
| 932 | \& print ++$x,"\en"; |
| 933 | .Ve |
| 934 | .Sp |
| 935 | .Vb 2 |
| 936 | \& # perl4 prints: aab : -0 : 1 |
| 937 | \& # perl5 prints: aab : -aab : aac |
| 938 | .Ve |
| 939 | .IP "* Modifying of constants prohibited" 5 |
| 940 | .IX Item "Modifying of constants prohibited" |
| 941 | perl 4 lets you modify constants: |
| 942 | .Sp |
| 943 | .Vb 10 |
| 944 | \& $foo = "x"; |
| 945 | \& &mod($foo); |
| 946 | \& for ($x = 0; $x < 3; $x++) { |
| 947 | \& &mod("a"); |
| 948 | \& } |
| 949 | \& sub mod { |
| 950 | \& print "before: $_[0]"; |
| 951 | \& $_[0] = "m"; |
| 952 | \& print " after: $_[0]\en"; |
| 953 | \& } |
| 954 | .Ve |
| 955 | .Sp |
| 956 | .Vb 5 |
| 957 | \& # perl4: |
| 958 | \& # before: x after: m |
| 959 | \& # before: a after: m |
| 960 | \& # before: m after: m |
| 961 | \& # before: m after: m |
| 962 | .Ve |
| 963 | .Sp |
| 964 | .Vb 4 |
| 965 | \& # Perl5: |
| 966 | \& # before: x after: m |
| 967 | \& # Modification of a read-only value attempted at foo.pl line 12. |
| 968 | \& # before: a |
| 969 | .Ve |
| 970 | .ie n .IP "* ""defined $var"" behavior changed" 5 |
| 971 | .el .IP "* \f(CWdefined $var\fR behavior changed" 5 |
| 972 | .IX Item "defined $var behavior changed" |
| 973 | The behavior is slightly different for: |
| 974 | .Sp |
| 975 | .Vb 1 |
| 976 | \& print "$x", defined $x |
| 977 | .Ve |
| 978 | .Sp |
| 979 | .Vb 2 |
| 980 | \& # perl 4: 1 |
| 981 | \& # perl 5: <no output, $x is not called into existence> |
| 982 | .Ve |
| 983 | .IP "* Variable Suicide" 5 |
| 984 | .IX Item "Variable Suicide" |
| 985 | Variable suicide behavior is more consistent under Perl 5. |
| 986 | Perl5 exhibits the same behavior for hashes and scalars, |
| 987 | that perl4 exhibits for only scalars. |
| 988 | .Sp |
| 989 | .Vb 4 |
| 990 | \& $aGlobal{ "aKey" } = "global value"; |
| 991 | \& print "MAIN:", $aGlobal{"aKey"}, "\en"; |
| 992 | \& $GlobalLevel = 0; |
| 993 | \& &test( *aGlobal ); |
| 994 | .Ve |
| 995 | .Sp |
| 996 | .Vb 11 |
| 997 | \& sub test { |
| 998 | \& local( *theArgument ) = @_; |
| 999 | \& local( %aNewLocal ); # perl 4 != 5.001l,m |
| 1000 | \& $aNewLocal{"aKey"} = "this should never appear"; |
| 1001 | \& print "SUB: ", $theArgument{"aKey"}, "\en"; |
| 1002 | \& $aNewLocal{"aKey"} = "level $GlobalLevel"; # what should print |
| 1003 | \& $GlobalLevel++; |
| 1004 | \& if( $GlobalLevel<4 ) { |
| 1005 | \& &test( *aNewLocal ); |
| 1006 | \& } |
| 1007 | \& } |
| 1008 | .Ve |
| 1009 | .Sp |
| 1010 | .Vb 6 |
| 1011 | \& # Perl4: |
| 1012 | \& # MAIN:global value |
| 1013 | \& # SUB: global value |
| 1014 | \& # SUB: level 0 |
| 1015 | \& # SUB: level 1 |
| 1016 | \& # SUB: level 2 |
| 1017 | .Ve |
| 1018 | .Sp |
| 1019 | .Vb 6 |
| 1020 | \& # Perl5: |
| 1021 | \& # MAIN:global value |
| 1022 | \& # SUB: global value |
| 1023 | \& # SUB: this should never appear |
| 1024 | \& # SUB: this should never appear |
| 1025 | \& # SUB: this should never appear |
| 1026 | .Ve |
| 1027 | .Sh "Context Traps \- scalar, list contexts" |
| 1028 | .IX Subsection "Context Traps - scalar, list contexts" |
| 1029 | .IP "* Elements of argument lists for formats evaluated in list context" 5 |
| 1030 | .IX Item "Elements of argument lists for formats evaluated in list context" |
| 1031 | The elements of argument lists for formats are now evaluated in list |
| 1032 | context. This means you can interpolate list values now. |
| 1033 | .Sp |
| 1034 | .Vb 6 |
| 1035 | \& @fmt = ("foo","bar","baz"); |
| 1036 | \& format STDOUT= |
| 1037 | \& @<<<<< @||||| @>>>>> |
| 1038 | \& @fmt; |
| 1039 | \& . |
| 1040 | \& write; |
| 1041 | .Ve |
| 1042 | .Sp |
| 1043 | .Vb 2 |
| 1044 | \& # perl4 errors: Please use commas to separate fields in file |
| 1045 | \& # perl5 prints: foo bar baz |
| 1046 | .Ve |
| 1047 | .ie n .IP "* ""caller()"" returns false value in scalar context if no caller present" 5 |
| 1048 | .el .IP "* \f(CWcaller()\fR returns false value in scalar context if no caller present" 5 |
| 1049 | .IX Item "caller() returns false value in scalar context if no caller present" |
| 1050 | The \f(CW\*(C`caller()\*(C'\fR function now returns a false value in a scalar context |
| 1051 | if there is no caller. This lets library files determine if they're |
| 1052 | being required. |
| 1053 | .Sp |
| 1054 | .Vb 1 |
| 1055 | \& caller() ? (print "You rang?\en") : (print "Got a 0\en"); |
| 1056 | .Ve |
| 1057 | .Sp |
| 1058 | .Vb 2 |
| 1059 | \& # perl4 errors: There is no caller |
| 1060 | \& # perl5 prints: Got a 0 |
| 1061 | .Ve |
| 1062 | .IP "* Comma operator in scalar context gives scalar context to args" 5 |
| 1063 | .IX Item "Comma operator in scalar context gives scalar context to args" |
| 1064 | The comma operator in a scalar context is now guaranteed to give a |
| 1065 | scalar context to its arguments. |
| 1066 | .Sp |
| 1067 | .Vb 3 |
| 1068 | \& @y= ('a','b','c'); |
| 1069 | \& $x = (1, 2, @y); |
| 1070 | \& print "x = $x\en"; |
| 1071 | .Ve |
| 1072 | .Sp |
| 1073 | .Vb 2 |
| 1074 | \& # Perl4 prints: x = c # Thinks list context interpolates list |
| 1075 | \& # Perl5 prints: x = 3 # Knows scalar uses length of list |
| 1076 | .Ve |
| 1077 | .ie n .IP "* ""sprintf()""\fR prototyped as \f(CW""($;@)""" 5 |
| 1078 | .el .IP "* \f(CWsprintf()\fR prototyped as \f(CW($;@)\fR" 5 |
| 1079 | .IX Item "sprintf() prototyped as ($;@)" |
| 1080 | \&\f(CW\*(C`sprintf()\*(C'\fR is prototyped as ($;@), so its first argument is given scalar |
| 1081 | context. Thus, if passed an array, it will probably not do what you want, |
| 1082 | unlike Perl 4: |
| 1083 | .Sp |
| 1084 | .Vb 3 |
| 1085 | \& @z = ('%s%s', 'foo', 'bar'); |
| 1086 | \& $x = sprintf(@z); |
| 1087 | \& print $x; |
| 1088 | .Ve |
| 1089 | .Sp |
| 1090 | .Vb 2 |
| 1091 | \& # perl4 prints: foobar |
| 1092 | \& # perl5 prints: 3 |
| 1093 | .Ve |
| 1094 | .Sp |
| 1095 | \&\f(CW\*(C`printf()\*(C'\fR works the same as it did in Perl 4, though: |
| 1096 | .Sp |
| 1097 | .Vb 2 |
| 1098 | \& @z = ('%s%s', 'foo', 'bar'); |
| 1099 | \& printf STDOUT (@z); |
| 1100 | .Ve |
| 1101 | .Sp |
| 1102 | .Vb 2 |
| 1103 | \& # perl4 prints: foobar |
| 1104 | \& # perl5 prints: foobar |
| 1105 | .Ve |
| 1106 | .Sh "Precedence Traps" |
| 1107 | .IX Subsection "Precedence Traps" |
| 1108 | Perl4\-to\-Perl5 traps involving precedence order. |
| 1109 | .PP |
| 1110 | Perl 4 has almost the same precedence rules as Perl 5 for the operators |
| 1111 | that they both have. Perl 4 however, seems to have had some |
| 1112 | inconsistencies that made the behavior differ from what was documented. |
| 1113 | .IP "* \s-1LHS\s0 vs. \s-1RHS\s0 of any assignment operator" 5 |
| 1114 | .IX Item "LHS vs. RHS of any assignment operator" |
| 1115 | \&\s-1LHS\s0 vs. \s-1RHS\s0 of any assignment operator. \s-1LHS\s0 is evaluated first |
| 1116 | in perl4, second in perl5; this can affect the relationship |
| 1117 | between side-effects in sub\-expressions. |
| 1118 | .Sp |
| 1119 | .Vb 3 |
| 1120 | \& @arr = ( 'left', 'right' ); |
| 1121 | \& $a{shift @arr} = shift @arr; |
| 1122 | \& print join( ' ', keys %a ); |
| 1123 | .Ve |
| 1124 | .Sp |
| 1125 | .Vb 2 |
| 1126 | \& # perl4 prints: left |
| 1127 | \& # perl5 prints: right |
| 1128 | .Ve |
| 1129 | .IP "* Semantic errors introduced due to precedence" 5 |
| 1130 | .IX Item "Semantic errors introduced due to precedence" |
| 1131 | These are now semantic errors because of precedence: |
| 1132 | .Sp |
| 1133 | .Vb 6 |
| 1134 | \& @list = (1,2,3,4,5); |
| 1135 | \& %map = ("a",1,"b",2,"c",3,"d",4); |
| 1136 | \& $n = shift @list + 2; # first item in list plus 2 |
| 1137 | \& print "n is $n, "; |
| 1138 | \& $m = keys %map + 2; # number of items in hash plus 2 |
| 1139 | \& print "m is $m\en"; |
| 1140 | .Ve |
| 1141 | .Sp |
| 1142 | .Vb 2 |
| 1143 | \& # perl4 prints: n is 3, m is 6 |
| 1144 | \& # perl5 errors and fails to compile |
| 1145 | .Ve |
| 1146 | .IP "* Precedence of assignment operators same as the precedence of assignment" 5 |
| 1147 | .IX Item "Precedence of assignment operators same as the precedence of assignment" |
| 1148 | The precedence of assignment operators is now the same as the precedence |
| 1149 | of assignment. Perl 4 mistakenly gave them the precedence of the associated |
| 1150 | operator. So you now must parenthesize them in expressions like |
| 1151 | .Sp |
| 1152 | .Vb 1 |
| 1153 | \& /foo/ ? ($a += 2) : ($a -= 2); |
| 1154 | .Ve |
| 1155 | .Sp |
| 1156 | Otherwise |
| 1157 | .Sp |
| 1158 | .Vb 1 |
| 1159 | \& /foo/ ? $a += 2 : $a -= 2 |
| 1160 | .Ve |
| 1161 | .Sp |
| 1162 | would be erroneously parsed as |
| 1163 | .Sp |
| 1164 | .Vb 1 |
| 1165 | \& (/foo/ ? $a += 2 : $a) -= 2; |
| 1166 | .Ve |
| 1167 | .Sp |
| 1168 | On the other hand, |
| 1169 | .Sp |
| 1170 | .Vb 1 |
| 1171 | \& $a += /foo/ ? 1 : 2; |
| 1172 | .Ve |
| 1173 | .Sp |
| 1174 | now works as a C programmer would expect. |
| 1175 | .ie n .IP "* ""open"" requires parentheses around filehandle" 5 |
| 1176 | .el .IP "* \f(CWopen\fR requires parentheses around filehandle" 5 |
| 1177 | .IX Item "open requires parentheses around filehandle" |
| 1178 | .Vb 1 |
| 1179 | \& open FOO || die; |
| 1180 | .Ve |
| 1181 | .Sp |
| 1182 | is now incorrect. You need parentheses around the filehandle. |
| 1183 | Otherwise, perl5 leaves the statement as its default precedence: |
| 1184 | .Sp |
| 1185 | .Vb 1 |
| 1186 | \& open(FOO || die); |
| 1187 | .Ve |
| 1188 | .Sp |
| 1189 | .Vb 2 |
| 1190 | \& # perl4 opens or dies |
| 1191 | \& # perl5 opens FOO, dying only if 'FOO' is false, i.e. never |
| 1192 | .Ve |
| 1193 | .ie n .IP "* $:\fR precedence over \f(CW$:: gone" 5 |
| 1194 | .el .IP "* \f(CW$:\fR precedence over \f(CW$::\fR gone" 5 |
| 1195 | .IX Item "$: precedence over $:: gone" |
| 1196 | perl4 gives the special variable, \f(CW$:\fR precedence, where perl5 |
| 1197 | treats \f(CW$::\fR as main \f(CW\*(C`package\*(C'\fR |
| 1198 | .Sp |
| 1199 | .Vb 1 |
| 1200 | \& $a = "x"; print "$::a"; |
| 1201 | .Ve |
| 1202 | .Sp |
| 1203 | .Vb 2 |
| 1204 | \& # perl 4 prints: -:a |
| 1205 | \& # perl 5 prints: x |
| 1206 | .Ve |
| 1207 | .IP "* Precedence of file test operators documented" 5 |
| 1208 | .IX Item "Precedence of file test operators documented" |
| 1209 | perl4 had buggy precedence for the file test operators vis-a-vis |
| 1210 | the assignment operators. Thus, although the precedence table |
| 1211 | for perl4 leads one to believe \f(CW\*(C`\-e $foo .= "q"\*(C'\fR should parse as |
| 1212 | \&\f(CW\*(C`((\-e $foo) .= "q")\*(C'\fR, it actually parses as \f(CW\*(C`(\-e ($foo .= "q"))\*(C'\fR. |
| 1213 | In perl5, the precedence is as documented. |
| 1214 | .Sp |
| 1215 | .Vb 1 |
| 1216 | \& -e $foo .= "q" |
| 1217 | .Ve |
| 1218 | .Sp |
| 1219 | .Vb 2 |
| 1220 | \& # perl4 prints: no output |
| 1221 | \& # perl5 prints: Can't modify -e in concatenation |
| 1222 | .Ve |
| 1223 | .ie n .IP "* ""keys""\fR, \f(CW""each""\fR, \f(CW""values"" are regular named unary operators" 5 |
| 1224 | .el .IP "* \f(CWkeys\fR, \f(CWeach\fR, \f(CWvalues\fR are regular named unary operators" 5 |
| 1225 | .IX Item "keys, each, values are regular named unary operators" |
| 1226 | In perl4, \fIkeys()\fR, \fIeach()\fR and \fIvalues()\fR were special high-precedence operators |
| 1227 | that operated on a single hash, but in perl5, they are regular named unary |
| 1228 | operators. As documented, named unary operators have lower precedence |
| 1229 | than the arithmetic and concatenation operators \f(CW\*(C`+ \- .\*(C'\fR, but the perl4 |
| 1230 | variants of these operators actually bind tighter than \f(CW\*(C`+ \- .\*(C'\fR. |
| 1231 | Thus, for: |
| 1232 | .Sp |
| 1233 | .Vb 2 |
| 1234 | \& %foo = 1..10; |
| 1235 | \& print keys %foo - 1 |
| 1236 | .Ve |
| 1237 | .Sp |
| 1238 | .Vb 2 |
| 1239 | \& # perl4 prints: 4 |
| 1240 | \& # perl5 prints: Type of arg 1 to keys must be hash (not subtraction) |
| 1241 | .Ve |
| 1242 | .Sp |
| 1243 | The perl4 behavior was probably more useful, if less consistent. |
| 1244 | .Sh "General Regular Expression Traps using s///, etc." |
| 1245 | .IX Subsection "General Regular Expression Traps using s///, etc." |
| 1246 | All types of \s-1RE\s0 traps. |
| 1247 | .ie n .IP "* ""s'$lhs'$rhs'"" interpolates on either side" 5 |
| 1248 | .el .IP "* \f(CWs'$lhs'$rhs'\fR interpolates on either side" 5 |
| 1249 | .IX Item "s'$lhs'$rhs' interpolates on either side" |
| 1250 | \&\f(CW\*(C`s'$lhs'$rhs'\*(C'\fR now does no interpolation on either side. It used to |
| 1251 | interpolate \f(CW$lhs\fR but not \f(CW$rhs\fR. (And still does not match a literal |
| 1252 | \&'$' in string) |
| 1253 | .Sp |
| 1254 | .Vb 4 |
| 1255 | \& $a=1;$b=2; |
| 1256 | \& $string = '1 2 $a $b'; |
| 1257 | \& $string =~ s'$a'$b'; |
| 1258 | \& print $string,"\en"; |
| 1259 | .Ve |
| 1260 | .Sp |
| 1261 | .Vb 2 |
| 1262 | \& # perl4 prints: $b 2 $a $b |
| 1263 | \& # perl5 prints: 1 2 $a $b |
| 1264 | .Ve |
| 1265 | .ie n .IP "* ""m//g"" attaches its state to the searched string" 5 |
| 1266 | .el .IP "* \f(CWm//g\fR attaches its state to the searched string" 5 |
| 1267 | .IX Item "m//g attaches its state to the searched string" |
| 1268 | \&\f(CW\*(C`m//g\*(C'\fR now attaches its state to the searched string rather than the |
| 1269 | regular expression. (Once the scope of a block is left for the sub, the |
| 1270 | state of the searched string is lost) |
| 1271 | .Sp |
| 1272 | .Vb 5 |
| 1273 | \& $_ = "ababab"; |
| 1274 | \& while(m/ab/g){ |
| 1275 | \& &doit("blah"); |
| 1276 | \& } |
| 1277 | \& sub doit{local($_) = shift; print "Got $_ "} |
| 1278 | .Ve |
| 1279 | .Sp |
| 1280 | .Vb 2 |
| 1281 | \& # perl4 prints: Got blah Got blah Got blah Got blah |
| 1282 | \& # perl5 prints: infinite loop blah... |
| 1283 | .Ve |
| 1284 | .ie n .IP "* ""m//o"" used within an anonymous sub" 5 |
| 1285 | .el .IP "* \f(CWm//o\fR used within an anonymous sub" 5 |
| 1286 | .IX Item "m//o used within an anonymous sub" |
| 1287 | Currently, if you use the \f(CW\*(C`m//o\*(C'\fR qualifier on a regular expression |
| 1288 | within an anonymous sub, \fIall\fR closures generated from that anonymous |
| 1289 | sub will use the regular expression as it was compiled when it was used |
| 1290 | the very first time in any such closure. For instance, if you say |
| 1291 | .Sp |
| 1292 | .Vb 9 |
| 1293 | \& sub build_match { |
| 1294 | \& my($left,$right) = @_; |
| 1295 | \& return sub { $_[0] =~ /$left stuff $right/o; }; |
| 1296 | \& } |
| 1297 | \& $good = build_match('foo','bar'); |
| 1298 | \& $bad = build_match('baz','blarch'); |
| 1299 | \& print $good->('foo stuff bar') ? "ok\en" : "not ok\en"; |
| 1300 | \& print $bad->('baz stuff blarch') ? "ok\en" : "not ok\en"; |
| 1301 | \& print $bad->('foo stuff bar') ? "not ok\en" : "ok\en"; |
| 1302 | .Ve |
| 1303 | .Sp |
| 1304 | For most builds of Perl5, this will print: |
| 1305 | ok |
| 1306 | not ok |
| 1307 | not ok |
| 1308 | .Sp |
| 1309 | \&\fIbuild_match()\fR will always return a sub which matches the contents of |
| 1310 | \&\f(CW$left\fR and \f(CW$right\fR as they were the \fIfirst\fR time that \fIbuild_match()\fR |
| 1311 | was called, not as they are in the current call. |
| 1312 | .ie n .IP "* $+ isn't set to whole match" 5 |
| 1313 | .el .IP "* \f(CW$+\fR isn't set to whole match" 5 |
| 1314 | .IX Item "$+ isn't set to whole match" |
| 1315 | If no parentheses are used in a match, Perl4 sets \f(CW$+\fR to |
| 1316 | the whole match, just like \f(CW$&\fR. Perl5 does not. |
| 1317 | .Sp |
| 1318 | .Vb 2 |
| 1319 | \& "abcdef" =~ /b.*e/; |
| 1320 | \& print "\e$+ = $+\en"; |
| 1321 | .Ve |
| 1322 | .Sp |
| 1323 | .Vb 2 |
| 1324 | \& # perl4 prints: bcde |
| 1325 | \& # perl5 prints: |
| 1326 | .Ve |
| 1327 | .IP "* Substitution now returns null string if it fails" 5 |
| 1328 | .IX Item "Substitution now returns null string if it fails" |
| 1329 | substitution now returns the null string if it fails |
| 1330 | .Sp |
| 1331 | .Vb 3 |
| 1332 | \& $string = "test"; |
| 1333 | \& $value = ($string =~ s/foo//); |
| 1334 | \& print $value, "\en"; |
| 1335 | .Ve |
| 1336 | .Sp |
| 1337 | .Vb 2 |
| 1338 | \& # perl4 prints: 0 |
| 1339 | \& # perl5 prints: |
| 1340 | .Ve |
| 1341 | .Sp |
| 1342 | Also see \*(L"Numerical Traps\*(R" for another example of this new feature. |
| 1343 | .ie n .IP "* ""s`lhs`rhs`"" is now a normal substitution" 5 |
| 1344 | .el .IP "* \f(CWs`lhs`rhs`\fR is now a normal substitution" 5 |
| 1345 | .IX Item "s`lhs`rhs` is now a normal substitution" |
| 1346 | \&\f(CW\*(C`s`lhs`rhs`\*(C'\fR (using backticks) is now a normal substitution, with no |
| 1347 | backtick expansion |
| 1348 | .Sp |
| 1349 | .Vb 3 |
| 1350 | \& $string = ""; |
| 1351 | \& $string =~ s`^`hostname`; |
| 1352 | \& print $string, "\en"; |
| 1353 | .Ve |
| 1354 | .Sp |
| 1355 | .Vb 2 |
| 1356 | \& # perl4 prints: <the local hostname> |
| 1357 | \& # perl5 prints: hostname |
| 1358 | .Ve |
| 1359 | .IP "* Stricter parsing of variables in regular expressions" 5 |
| 1360 | .IX Item "Stricter parsing of variables in regular expressions" |
| 1361 | Stricter parsing of variables used in regular expressions |
| 1362 | .Sp |
| 1363 | .Vb 1 |
| 1364 | \& s/^([^$grpc]*$grpc[$opt$plus$rep]?)//o; |
| 1365 | .Ve |
| 1366 | .Sp |
| 1367 | .Vb 2 |
| 1368 | \& # perl4: compiles w/o error |
| 1369 | \& # perl5: with Scalar found where operator expected ..., near "$opt$plus" |
| 1370 | .Ve |
| 1371 | .Sp |
| 1372 | an added component of this example, apparently from the same script, is |
| 1373 | the actual value of the s'd string after the substitution. |
| 1374 | \&\f(CW\*(C`[$opt]\*(C'\fR is a character class in perl4 and an array subscript in perl5 |
| 1375 | .Sp |
| 1376 | .Vb 5 |
| 1377 | \& $grpc = 'a'; |
| 1378 | \& $opt = 'r'; |
| 1379 | \& $_ = 'bar'; |
| 1380 | \& s/^([^$grpc]*$grpc[$opt]?)/foo/; |
| 1381 | \& print; |
| 1382 | .Ve |
| 1383 | .Sp |
| 1384 | .Vb 2 |
| 1385 | \& # perl4 prints: foo |
| 1386 | \& # perl5 prints: foobar |
| 1387 | .Ve |
| 1388 | .ie n .IP "* ""m?x?"" matches only once" 5 |
| 1389 | .el .IP "* \f(CWm?x?\fR matches only once" 5 |
| 1390 | .IX Item "m?x? matches only once" |
| 1391 | Under perl5, \f(CW\*(C`m?x?\*(C'\fR matches only once, like \f(CW\*(C`?x?\*(C'\fR. Under perl4, it matched |
| 1392 | repeatedly, like \f(CW\*(C`/x/\*(C'\fR or \f(CW\*(C`m!x!\*(C'\fR. |
| 1393 | .Sp |
| 1394 | .Vb 10 |
| 1395 | \& $test = "once"; |
| 1396 | \& sub match { $test =~ m?once?; } |
| 1397 | \& &match(); |
| 1398 | \& if( &match() ) { |
| 1399 | \& # m?x? matches more then once |
| 1400 | \& print "perl4\en"; |
| 1401 | \& } else { |
| 1402 | \& # m?x? matches only once |
| 1403 | \& print "perl5\en"; |
| 1404 | \& } |
| 1405 | .Ve |
| 1406 | .Sp |
| 1407 | .Vb 2 |
| 1408 | \& # perl4 prints: perl4 |
| 1409 | \& # perl5 prints: perl5 |
| 1410 | .Ve |
| 1411 | .IP "* Failed matches don't reset the match variables" 5 |
| 1412 | .IX Item "Failed matches don't reset the match variables" |
| 1413 | Unlike in Ruby, failed matches in Perl do not reset the match variables |
| 1414 | ($1, \f(CW$2\fR, ..., \f(CW$`\fR, ...). |
| 1415 | .Sh "Subroutine, Signal, Sorting Traps" |
| 1416 | .IX Subsection "Subroutine, Signal, Sorting Traps" |
| 1417 | The general group of Perl4\-to\-Perl5 traps having to do with |
| 1418 | Signals, Sorting, and their related subroutines, as well as |
| 1419 | general subroutine traps. Includes some OS-Specific traps. |
| 1420 | .IP "* Barewords that used to look like strings look like subroutine calls" 5 |
| 1421 | .IX Item "Barewords that used to look like strings look like subroutine calls" |
| 1422 | Barewords that used to look like strings to Perl will now look like subroutine |
| 1423 | calls if a subroutine by that name is defined before the compiler sees them. |
| 1424 | .Sp |
| 1425 | .Vb 3 |
| 1426 | \& sub SeeYa { warn"Hasta la vista, baby!" } |
| 1427 | \& $SIG{'TERM'} = SeeYa; |
| 1428 | \& print "SIGTERM is now $SIG{'TERM'}\en"; |
| 1429 | .Ve |
| 1430 | .Sp |
| 1431 | .Vb 2 |
| 1432 | \& # perl4 prints: SIGTERM is now main'SeeYa |
| 1433 | \& # perl5 prints: SIGTERM is now main::1 (and warns "Hasta la vista, baby!") |
| 1434 | .Ve |
| 1435 | .Sp |
| 1436 | Use \fB\-w\fR to catch this one |
| 1437 | .IP "* Reverse is no longer allowed as the name of a sort subroutine" 5 |
| 1438 | .IX Item "Reverse is no longer allowed as the name of a sort subroutine" |
| 1439 | reverse is no longer allowed as the name of a sort subroutine. |
| 1440 | .Sp |
| 1441 | .Vb 2 |
| 1442 | \& sub reverse{ print "yup "; $a <=> $b } |
| 1443 | \& print sort reverse (2,1,3); |
| 1444 | .Ve |
| 1445 | .Sp |
| 1446 | .Vb 3 |
| 1447 | \& # perl4 prints: yup yup 123 |
| 1448 | \& # perl5 prints: 123 |
| 1449 | \& # perl5 warns (if using -w): Ambiguous call resolved as CORE::reverse() |
| 1450 | .Ve |
| 1451 | .ie n .IP "* ""warn()"" won't let you specify a filehandle." 5 |
| 1452 | .el .IP "* \f(CWwarn()\fR won't let you specify a filehandle." 5 |
| 1453 | .IX Item "warn() won't let you specify a filehandle." |
| 1454 | Although it _always_ printed to \s-1STDERR\s0, \fIwarn()\fR would let you specify a |
| 1455 | filehandle in perl4. With perl5 it does not. |
| 1456 | .Sp |
| 1457 | .Vb 1 |
| 1458 | \& warn STDERR "Foo!"; |
| 1459 | .Ve |
| 1460 | .Sp |
| 1461 | .Vb 2 |
| 1462 | \& # perl4 prints: Foo! |
| 1463 | \& # perl5 prints: String found where operator expected |
| 1464 | .Ve |
| 1465 | .Sh "\s-1OS\s0 Traps" |
| 1466 | .IX Subsection "OS Traps" |
| 1467 | .IP "* SysV resets signal handler correctly" 5 |
| 1468 | .IX Item "SysV resets signal handler correctly" |
| 1469 | Under \s-1HPUX\s0, and some other SysV OSes, one had to reset any signal handler, |
| 1470 | within the signal handler function, each time a signal was handled with |
| 1471 | perl4. With perl5, the reset is now done correctly. Any code relying |
| 1472 | on the handler _not_ being reset will have to be reworked. |
| 1473 | .Sp |
| 1474 | Since version 5.002, Perl uses \fIsigaction()\fR under SysV. |
| 1475 | .Sp |
| 1476 | .Vb 4 |
| 1477 | \& sub gotit { |
| 1478 | \& print "Got @_... "; |
| 1479 | \& } |
| 1480 | \& $SIG{'INT'} = 'gotit'; |
| 1481 | .Ve |
| 1482 | .Sp |
| 1483 | .Vb 9 |
| 1484 | \& $| = 1; |
| 1485 | \& $pid = fork; |
| 1486 | \& if ($pid) { |
| 1487 | \& kill('INT', $pid); |
| 1488 | \& sleep(1); |
| 1489 | \& kill('INT', $pid); |
| 1490 | \& } else { |
| 1491 | \& while (1) {sleep(10);} |
| 1492 | \& } |
| 1493 | .Ve |
| 1494 | .Sp |
| 1495 | .Vb 2 |
| 1496 | \& # perl4 (HPUX) prints: Got INT... |
| 1497 | \& # perl5 (HPUX) prints: Got INT... Got INT... |
| 1498 | .Ve |
| 1499 | .ie n .IP "* SysV ""seek()"" appends correctly" 5 |
| 1500 | .el .IP "* SysV \f(CWseek()\fR appends correctly" 5 |
| 1501 | .IX Item "SysV seek() appends correctly" |
| 1502 | Under SysV OSes, \f(CW\*(C`seek()\*(C'\fR on a file opened to append \f(CW\*(C`>>\*(C'\fR now does |
| 1503 | the right thing w.r.t. the \fIfopen()\fR manpage. e.g., \- When a file is opened |
| 1504 | for append, it is impossible to overwrite information already in |
| 1505 | the file. |
| 1506 | .Sp |
| 1507 | .Vb 8 |
| 1508 | \& open(TEST,">>seek.test"); |
| 1509 | \& $start = tell TEST; |
| 1510 | \& foreach(1 .. 9){ |
| 1511 | \& print TEST "$_ "; |
| 1512 | \& } |
| 1513 | \& $end = tell TEST; |
| 1514 | \& seek(TEST,$start,0); |
| 1515 | \& print TEST "18 characters here"; |
| 1516 | .Ve |
| 1517 | .Sp |
| 1518 | .Vb 2 |
| 1519 | \& # perl4 (solaris) seek.test has: 18 characters here |
| 1520 | \& # perl5 (solaris) seek.test has: 1 2 3 4 5 6 7 8 9 18 characters here |
| 1521 | .Ve |
| 1522 | .Sh "Interpolation Traps" |
| 1523 | .IX Subsection "Interpolation Traps" |
| 1524 | Perl4\-to\-Perl5 traps having to do with how things get interpolated |
| 1525 | within certain expressions, statements, contexts, or whatever. |
| 1526 | .ie n .IP "* ""@"" always interpolates an array in double-quotish strings" 5 |
| 1527 | .el .IP "* \f(CW@\fR always interpolates an array in double-quotish strings" 5 |
| 1528 | .IX Item "@ always interpolates an array in double-quotish strings" |
| 1529 | @ now always interpolates an array in double-quotish strings. |
| 1530 | .Sp |
| 1531 | .Vb 1 |
| 1532 | \& print "To: someone@somewhere.com\en"; |
| 1533 | .Ve |
| 1534 | .Sp |
| 1535 | .Vb 3 |
| 1536 | \& # perl4 prints: To:someone@somewhere.com |
| 1537 | \& # perl < 5.6.1, error : In string, @somewhere now must be written as \e@somewhere |
| 1538 | \& # perl >= 5.6.1, warning : Possible unintended interpolation of @somewhere in string |
| 1539 | .Ve |
| 1540 | .IP "* Double-quoted strings may no longer end with an unescaped $" 5 |
| 1541 | .IX Item "Double-quoted strings may no longer end with an unescaped $" |
| 1542 | Double-quoted strings may no longer end with an unescaped $. |
| 1543 | .Sp |
| 1544 | .Vb 2 |
| 1545 | \& $foo = "foo$"; |
| 1546 | \& print "foo is $foo\en"; |
| 1547 | .Ve |
| 1548 | .Sp |
| 1549 | .Vb 2 |
| 1550 | \& # perl4 prints: foo is foo$ |
| 1551 | \& # perl5 errors: Final $ should be \e$ or $name |
| 1552 | .Ve |
| 1553 | .Sp |
| 1554 | Note: perl5 \s-1DOES\s0 \s-1NOT\s0 error on the terminating @ in \f(CW$bar\fR |
| 1555 | .IP "* Arbitrary expressions are evaluated inside braces within double quotes" 5 |
| 1556 | .IX Item "Arbitrary expressions are evaluated inside braces within double quotes" |
| 1557 | Perl now sometimes evaluates arbitrary expressions inside braces that occur |
| 1558 | within double quotes (usually when the opening brace is preceded by \f(CW\*(C`$\*(C'\fR |
| 1559 | or \f(CW\*(C`@\*(C'\fR). |
| 1560 | .Sp |
| 1561 | .Vb 5 |
| 1562 | \& @www = "buz"; |
| 1563 | \& $foo = "foo"; |
| 1564 | \& $bar = "bar"; |
| 1565 | \& sub foo { return "bar" }; |
| 1566 | \& print "|@{w.w.w}|${main'foo}|"; |
| 1567 | .Ve |
| 1568 | .Sp |
| 1569 | .Vb 2 |
| 1570 | \& # perl4 prints: |@{w.w.w}|foo| |
| 1571 | \& # perl5 prints: |buz|bar| |
| 1572 | .Ve |
| 1573 | .Sp |
| 1574 | Note that you can \f(CW\*(C`use strict;\*(C'\fR to ward off such trappiness under perl5. |
| 1575 | .ie n .IP "* $$x\fR now tries to dereference \f(CW$x" 5 |
| 1576 | .el .IP "* \f(CW$$x\fR now tries to dereference \f(CW$x\fR" 5 |
| 1577 | .IX Item "$$x now tries to dereference $x" |
| 1578 | The construct \*(L"this is $$x\*(R" used to interpolate the pid at that point, but |
| 1579 | now tries to dereference \f(CW$x\fR. \f(CW$$\fR by itself still works fine, however. |
| 1580 | .Sp |
| 1581 | .Vb 3 |
| 1582 | \& $s = "a reference"; |
| 1583 | \& $x = *s; |
| 1584 | \& print "this is $$x\en"; |
| 1585 | .Ve |
| 1586 | .Sp |
| 1587 | .Vb 2 |
| 1588 | \& # perl4 prints: this is XXXx (XXX is the current pid) |
| 1589 | \& # perl5 prints: this is a reference |
| 1590 | .Ve |
| 1591 | .ie n .IP "* Creation of hashes on the fly with ""eval ""EXPR"""" requires protection" 5 |
| 1592 | .el .IP "* Creation of hashes on the fly with \f(CWeval ``EXPR''\fR requires protection" 5 |
| 1593 | .IX Item "Creation of hashes on the fly with eval ""EXPR"" requires protection" |
| 1594 | Creation of hashes on the fly with \f(CW\*(C`eval "EXPR"\*(C'\fR now requires either both |
| 1595 | \&\f(CW\*(C`$\*(C'\fR's to be protected in the specification of the hash name, or both curlies |
| 1596 | to be protected. If both curlies are protected, the result will be compatible |
| 1597 | with perl4 and perl5. This is a very common practice, and should be changed |
| 1598 | to use the block form of \f(CW\*(C`eval{}\*(C'\fR if possible. |
| 1599 | .Sp |
| 1600 | .Vb 5 |
| 1601 | \& $hashname = "foobar"; |
| 1602 | \& $key = "baz"; |
| 1603 | \& $value = 1234; |
| 1604 | \& eval "\e$$hashname{'$key'} = q|$value|"; |
| 1605 | \& (defined($foobar{'baz'})) ? (print "Yup") : (print "Nope"); |
| 1606 | .Ve |
| 1607 | .Sp |
| 1608 | .Vb 2 |
| 1609 | \& # perl4 prints: Yup |
| 1610 | \& # perl5 prints: Nope |
| 1611 | .Ve |
| 1612 | .Sp |
| 1613 | Changing |
| 1614 | .Sp |
| 1615 | .Vb 1 |
| 1616 | \& eval "\e$$hashname{'$key'} = q|$value|"; |
| 1617 | .Ve |
| 1618 | .Sp |
| 1619 | to |
| 1620 | .Sp |
| 1621 | .Vb 1 |
| 1622 | \& eval "\e$\e$hashname{'$key'} = q|$value|"; |
| 1623 | .Ve |
| 1624 | .Sp |
| 1625 | causes the following result: |
| 1626 | .Sp |
| 1627 | .Vb 2 |
| 1628 | \& # perl4 prints: Nope |
| 1629 | \& # perl5 prints: Yup |
| 1630 | .Ve |
| 1631 | .Sp |
| 1632 | or, changing to |
| 1633 | .Sp |
| 1634 | .Vb 1 |
| 1635 | \& eval "\e$$hashname\e{'$key'\e} = q|$value|"; |
| 1636 | .Ve |
| 1637 | .Sp |
| 1638 | causes the following result: |
| 1639 | .Sp |
| 1640 | .Vb 3 |
| 1641 | \& # perl4 prints: Yup |
| 1642 | \& # perl5 prints: Yup |
| 1643 | \& # and is compatible for both versions |
| 1644 | .Ve |
| 1645 | .IP "* Bugs in earlier perl versions" 5 |
| 1646 | .IX Item "Bugs in earlier perl versions" |
| 1647 | perl4 programs which unconsciously rely on the bugs in earlier perl versions. |
| 1648 | .Sp |
| 1649 | .Vb 1 |
| 1650 | \& perl -e '$bar=q/not/; print "This is $foo{$bar} perl5"' |
| 1651 | .Ve |
| 1652 | .Sp |
| 1653 | .Vb 2 |
| 1654 | \& # perl4 prints: This is not perl5 |
| 1655 | \& # perl5 prints: This is perl5 |
| 1656 | .Ve |
| 1657 | .IP "* Array and hash brackets during interpolation" 5 |
| 1658 | .IX Item "Array and hash brackets during interpolation" |
| 1659 | You also have to be careful about array and hash brackets during |
| 1660 | interpolation. |
| 1661 | .Sp |
| 1662 | .Vb 1 |
| 1663 | \& print "$foo[" |
| 1664 | .Ve |
| 1665 | .Sp |
| 1666 | .Vb 2 |
| 1667 | \& perl 4 prints: [ |
| 1668 | \& perl 5 prints: syntax error |
| 1669 | .Ve |
| 1670 | .Sp |
| 1671 | .Vb 1 |
| 1672 | \& print "$foo{" |
| 1673 | .Ve |
| 1674 | .Sp |
| 1675 | .Vb 2 |
| 1676 | \& perl 4 prints: { |
| 1677 | \& perl 5 prints: syntax error |
| 1678 | .Ve |
| 1679 | .Sp |
| 1680 | Perl 5 is expecting to find an index or key name following the respective |
| 1681 | brackets, as well as an ending bracket of the appropriate type. In order |
| 1682 | to mimic the behavior of Perl 4, you must escape the bracket like so. |
| 1683 | .Sp |
| 1684 | .Vb 2 |
| 1685 | \& print "$foo\e["; |
| 1686 | \& print "$foo\e{"; |
| 1687 | .Ve |
| 1688 | .ie n .IP "* Interpolation of ""\e$$foo{bar}""" 5 |
| 1689 | .el .IP "* Interpolation of \f(CW\e$$foo{bar}\fR" 5 |
| 1690 | .IX Item "Interpolation of $$foo{bar}" |
| 1691 | Similarly, watch out for: \f(CW\*(C`\e$$foo{bar}\*(C'\fR |
| 1692 | .Sp |
| 1693 | .Vb 2 |
| 1694 | \& $foo = "baz"; |
| 1695 | \& print "\e$$foo{bar}\en"; |
| 1696 | .Ve |
| 1697 | .Sp |
| 1698 | .Vb 2 |
| 1699 | \& # perl4 prints: $baz{bar} |
| 1700 | \& # perl5 prints: $ |
| 1701 | .Ve |
| 1702 | .Sp |
| 1703 | Perl 5 is looking for \f(CW$foo{bar}\fR which doesn't exist, but perl 4 is |
| 1704 | happy just to expand \f(CW$foo\fR to \*(L"baz\*(R" by itself. Watch out for this |
| 1705 | especially in \f(CW\*(C`eval\*(C'\fR's. |
| 1706 | .ie n .IP "* ""qq()""\fR string passed to \f(CW""eval"" will not find string terminator" 5 |
| 1707 | .el .IP "* \f(CWqq()\fR string passed to \f(CWeval\fR will not find string terminator" 5 |
| 1708 | .IX Item "qq() string passed to eval will not find string terminator" |
| 1709 | \&\f(CW\*(C`qq()\*(C'\fR string passed to \f(CW\*(C`eval\*(C'\fR |
| 1710 | .Sp |
| 1711 | .Vb 5 |
| 1712 | \& eval qq( |
| 1713 | \& foreach \e$y (keys %\e$x\e) { |
| 1714 | \& \e$count++; |
| 1715 | \& } |
| 1716 | \& ); |
| 1717 | .Ve |
| 1718 | .Sp |
| 1719 | .Vb 2 |
| 1720 | \& # perl4 runs this ok |
| 1721 | \& # perl5 prints: Can't find string terminator ")" |
| 1722 | .Ve |
| 1723 | .Sh "\s-1DBM\s0 Traps" |
| 1724 | .IX Subsection "DBM Traps" |
| 1725 | General \s-1DBM\s0 traps. |
| 1726 | .ie n .IP "* Perl5 must have been linked with same dbm/ndbm as the default for ""dbmopen()""" 5 |
| 1727 | .el .IP "* Perl5 must have been linked with same dbm/ndbm as the default for \f(CWdbmopen()\fR" 5 |
| 1728 | .IX Item "Perl5 must have been linked with same dbm/ndbm as the default for dbmopen()" |
| 1729 | Existing dbm databases created under perl4 (or any other dbm/ndbm tool) |
| 1730 | may cause the same script, run under perl5, to fail. The build of perl5 |
| 1731 | must have been linked with the same dbm/ndbm as the default for \f(CW\*(C`dbmopen()\*(C'\fR |
| 1732 | to function properly without \f(CW\*(C`tie\*(C'\fR'ing to an extension dbm implementation. |
| 1733 | .Sp |
| 1734 | .Vb 2 |
| 1735 | \& dbmopen (%dbm, "file", undef); |
| 1736 | \& print "ok\en"; |
| 1737 | .Ve |
| 1738 | .Sp |
| 1739 | .Vb 2 |
| 1740 | \& # perl4 prints: ok |
| 1741 | \& # perl5 prints: ok (IFF linked with -ldbm or -lndbm) |
| 1742 | .Ve |
| 1743 | .IP "* \s-1DBM\s0 exceeding limit on the key/value size will cause perl5 to exit immediately" 5 |
| 1744 | .IX Item "DBM exceeding limit on the key/value size will cause perl5 to exit immediately" |
| 1745 | Existing dbm databases created under perl4 (or any other dbm/ndbm tool) |
| 1746 | may cause the same script, run under perl5, to fail. The error generated |
| 1747 | when exceeding the limit on the key/value size will cause perl5 to exit |
| 1748 | immediately. |
| 1749 | .Sp |
| 1750 | .Vb 3 |
| 1751 | \& dbmopen(DB, "testdb",0600) || die "couldn't open db! $!"; |
| 1752 | \& $DB{'trap'} = "x" x 1024; # value too large for most dbm/ndbm |
| 1753 | \& print "YUP\en"; |
| 1754 | .Ve |
| 1755 | .Sp |
| 1756 | .Vb 3 |
| 1757 | \& # perl4 prints: |
| 1758 | \& dbm store returned -1, errno 28, key "trap" at - line 3. |
| 1759 | \& YUP |
| 1760 | .Ve |
| 1761 | .Sp |
| 1762 | .Vb 2 |
| 1763 | \& # perl5 prints: |
| 1764 | \& dbm store returned -1, errno 28, key "trap" at - line 3. |
| 1765 | .Ve |
| 1766 | .Sh "Unclassified Traps" |
| 1767 | .IX Subsection "Unclassified Traps" |
| 1768 | Everything else. |
| 1769 | .ie n .IP "* ""require""\fR/\f(CW""do"" trap using returned value" 5 |
| 1770 | .el .IP "* \f(CWrequire\fR/\f(CWdo\fR trap using returned value" 5 |
| 1771 | .IX Item "require/do trap using returned value" |
| 1772 | If the file doit.pl has: |
| 1773 | .Sp |
| 1774 | .Vb 5 |
| 1775 | \& sub foo { |
| 1776 | \& $rc = do "./do.pl"; |
| 1777 | \& return 8; |
| 1778 | \& } |
| 1779 | \& print &foo, "\en"; |
| 1780 | .Ve |
| 1781 | .Sp |
| 1782 | And the do.pl file has the following single line: |
| 1783 | .Sp |
| 1784 | .Vb 1 |
| 1785 | \& return 3; |
| 1786 | .Ve |
| 1787 | .Sp |
| 1788 | Running doit.pl gives the following: |
| 1789 | .Sp |
| 1790 | .Vb 2 |
| 1791 | \& # perl 4 prints: 3 (aborts the subroutine early) |
| 1792 | \& # perl 5 prints: 8 |
| 1793 | .Ve |
| 1794 | .Sp |
| 1795 | Same behavior if you replace \f(CW\*(C`do\*(C'\fR with \f(CW\*(C`require\*(C'\fR. |
| 1796 | .ie n .IP "* ""split"" on empty string with \s-1LIMIT\s0 specified" 5 |
| 1797 | .el .IP "* \f(CWsplit\fR on empty string with \s-1LIMIT\s0 specified" 5 |
| 1798 | .IX Item "split on empty string with LIMIT specified" |
| 1799 | .Vb 2 |
| 1800 | \& $string = ''; |
| 1801 | \& @list = split(/foo/, $string, 2) |
| 1802 | .Ve |
| 1803 | .Sp |
| 1804 | Perl4 returns a one element list containing the empty string but Perl5 |
| 1805 | returns an empty list. |
| 1806 | .PP |
| 1807 | As always, if any of these are ever officially declared as bugs, |
| 1808 | they'll be fixed and removed. |