⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perltrap.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 4 页
字号:
\&\&    package main;\&    print "\e$_legacy is ",$_legacy,"\en";\&\&    # perl4 prints: $_legacy is 1\&    # perl5 prints: $_legacy is.Ve.IP "\(bu" 4Double-colon valid package separator in variable name.SpDouble-colon is now a valid package separator in a variable name.  Thus thesebehave differently in perl4 vs. perl5, because the packages don't exist..Sp.Vb 3\&    $a=1;$b=2;$c=3;$var=4;\&    print "$a::$b::$c ";\&    print "$var::abc::xyz\en";\&\&    # perl4 prints: 1::2::3 4::abc::xyz\&    # perl5 prints: 3.Ve.SpGiven that \f(CW\*(C`::\*(C'\fR is now the preferred package delimiter, it is debatablewhether this should be classed as a bug or not.(The older package delimiter, ' ,is used here).Sp.Vb 2\&    $x = 10;\&    print "x=${\*(Aqx}\en";\&\&    # perl4 prints: x=10\&    # perl5 prints: Can\*(Aqt find string terminator "\*(Aq" anywhere before EOF.Ve.SpYou can avoid this problem, and remain compatible with perl4, if youalways explicitly include the package name:.Sp.Vb 2\&    $x = 10;\&    print "x=${main\*(Aqx}\en";.Ve.SpAlso see precedence traps, for parsing \f(CW$:\fR..IP "\(bu" 42nd and 3rd args to \f(CW\*(C`splice()\*(C'\fR are now in scalar context.SpThe second and third arguments of \f(CW\*(C`splice()\*(C'\fR are now evaluated in scalarcontext (as the Camel says) rather than list context..Sp.Vb 5\&    sub sub1{return(0,2) }          # return a 2\-element list\&    sub sub2{ return(1,2,3)}        # return a 3\-element list\&    @a1 = ("a","b","c","d","e");\&    @a2 = splice(@a1,&sub1,&sub2);\&    print join(\*(Aq \*(Aq,@a2),"\en";\&\&    # perl4 prints: a b\&    # perl5 prints: c d e.Ve.IP "\(bu" 4Can't do \f(CW\*(C`goto\*(C'\fR into a block that is optimized away.SpYou can't do a \f(CW\*(C`goto\*(C'\fR into a block that is optimized away.  Darn..Sp.Vb 1\&    goto marker1;\&\&    for(1){\&    marker1:\&        print "Here I is!\en";\&    }\&\&    # perl4 prints: Here I is!\&    # perl5 errors: Can\*(Aqt "goto" into the middle of a foreach loop.Ve.IP "\(bu" 4Can't use whitespace as variable name or quote delimiter.SpIt is no longer syntactically legal to use whitespace as the nameof a variable, or as a delimiter for any kind of quote construct.Double darn..Sp.Vb 3\&    $a = ("foo bar");\&    $b = q baz;\&    print "a is $a, b is $b\en";\&\&    # perl4 prints: a is foo bar, b is baz\&    # perl5 errors: Bareword found where operator expected.Ve.IP "\(bu" 4\&\f(CW\*(C`while/if BLOCK BLOCK\*(C'\fR gone.SpThe archaic while/if \s-1BLOCK\s0 \s-1BLOCK\s0 syntax is no longer supported..Sp.Vb 6\&    if { 1 } {\&        print "True!";\&    }\&    else {\&        print "False!";\&    }\&\&    # perl4 prints: True!\&    # perl5 errors: syntax error at test.pl line 1, near "if {".Ve.IP "\(bu" 4\&\f(CW\*(C`**\*(C'\fR binds tighter than unary minus.SpThe \f(CW\*(C`**\*(C'\fR operator now binds more tightly than unary minus.It was documented to work this way before, but didn't..Sp.Vb 1\&    print \-4**2,"\en";\&\&    # perl4 prints: 16\&    # perl5 prints: \-16.Ve.IP "\(bu" 4\&\f(CW\*(C`foreach\*(C'\fR changed when iterating over a list.SpThe meaning of \f(CW\*(C`foreach{}\*(C'\fR has changed slightly when it is iterating over alist which is not an array.  This used to assign the list to atemporary array, but no longer does so (for efficiency).  This meansthat you'll now be iterating over the actual values, not over copies ofthe values.  Modifications to the loop variable can change the originalvalues..Sp.Vb 5\&    @list = (\*(Aqab\*(Aq,\*(Aqabc\*(Aq,\*(Aqbcd\*(Aq,\*(Aqdef\*(Aq);\&    foreach $var (grep(/ab/,@list)){\&        $var = 1;\&    }\&    print (join(\*(Aq:\*(Aq,@list));\&\&    # perl4 prints: ab:abc:bcd:def\&    # perl5 prints: 1:1:bcd:def.Ve.SpTo retain Perl4 semantics you need to assign your listexplicitly to a temporary array and then iterate over that.  Forexample, you might need to change.Sp.Vb 1\&    foreach $var (grep(/ab/,@list)){.Ve.Spto.Sp.Vb 1\&    foreach $var (@tmp = grep(/ab/,@list)){.Ve.SpOtherwise changing \f(CW$var\fR will clobber the values of \f(CW@list\fR.  (This most oftenhappens when you use \f(CW$_\fR for the loop variable, and call subroutines inthe loop that don't properly localize \f(CW$_\fR.).IP "\(bu" 4\&\f(CW\*(C`split\*(C'\fR with no args behavior changed.Sp\&\f(CW\*(C`split\*(C'\fR with no arguments now behaves like \f(CW\*(C`split \*(Aq \*(Aq\*(C'\fR (which doesn'treturn an initial null field if \f(CW$_\fR starts with whitespace), it used tobehave like \f(CW\*(C`split /\es+/\*(C'\fR (which does)..Sp.Vb 2\&    $_ = \*(Aq hi mom\*(Aq;\&    print join(\*(Aq:\*(Aq, split);\&\&    # perl4 prints: :hi:mom\&    # perl5 prints: hi:mom.Ve.IP "\(bu" 4\&\fB\-e\fR behavior fixed.SpPerl 4 would ignore any text which was attached to an \fB\-e\fR switch,always taking the code snippet from the following arg.  Additionally, itwould silently accept an \fB\-e\fR switch without a following arg.  Both ofthese behaviors have been fixed..Sp.Vb 1\&    perl \-e\*(Aqprint "attached to \-e"\*(Aq \*(Aqprint "separate arg"\*(Aq\&\&    # perl4 prints: separate arg\&    # perl5 prints: attached to \-e\&\&    perl \-e\&\&    # perl4 prints:\&    # perl5 dies: No code specified for \-e..Ve.IP "\(bu" 4\&\f(CW\*(C`push\*(C'\fR returns number of elements in resulting list.SpIn Perl 4 the return value of \f(CW\*(C`push\*(C'\fR was undocumented, but it wasactually the last value being pushed onto the target list.  In Perl 5the return value of \f(CW\*(C`push\*(C'\fR is documented, but has changed, it is thenumber of elements in the resulting list..Sp.Vb 2\&    @x = (\*(Aqexisting\*(Aq);\&    print push(@x, \*(Aqfirst new\*(Aq, \*(Aqsecond new\*(Aq);\&\&    # perl4 prints: second new\&    # perl5 prints: 3.Ve.IP "\(bu" 4Some error messages differ.SpSome error messages will be different..IP "\(bu" 4\&\f(CW\*(C`split()\*(C'\fR honors subroutine args.SpIn Perl 4, if in list context the delimiters to the first argument of\&\f(CW\*(C`split()\*(C'\fR were \f(CW\*(C`??\*(C'\fR, the result would be placed in \f(CW@_\fR as well asbeing returned.   Perl 5 has more respect for your subroutine arguments..IP "\(bu" 4Bugs removed.SpSome bugs may have been inadvertently removed.  :\-).Sh "Parsing Traps".IX Subsection "Parsing Traps"Perl4\-to\-Perl5 traps from having to do with parsing..IP "\(bu" 4Space between . and = triggers syntax error.SpNote the space between . and =.Sp.Vb 2\&    $string . = "more string";\&    print $string;\&\&    # perl4 prints: more string\&    # perl5 prints: syntax error at \- line 1, near ". =".Ve.IP "\(bu" 4Better parsing in perl 5.SpBetter parsing in perl 5.Sp.Vb 3\&    sub foo {}\&    &foo\&    print("hello, world\en");\&\&    # perl4 prints: hello, world\&    # perl5 prints: syntax error.Ve.IP "\(bu" 4Function parsing.Sp\&\*(L"if it looks like a function, it is a function\*(R" rule..Sp.Vb 2\&  print\&    ($foo == 1) ? "is one\en" : "is zero\en";\&\&    # perl4 prints: is zero\&    # perl5 warns: "Useless use of a constant in void context" if using \-w.Ve.IP "\(bu" 4String interpolation of \f(CW$#array\fR differs.SpString interpolation of the \f(CW$#array\fR construct differs when bracesare to used around the name..Sp.Vb 2\&    @a = (1..3);\&    print "${#a}";\&\&    # perl4 prints: 2\&    # perl5 fails with syntax error\&\&    @ = (1..3);\&    print "$#{a}";\&\&    # perl4 prints: {a}\&    # perl5 prints: 2.Ve.IP "\(bu" 4Perl guesses on \f(CW\*(C`map\*(C'\fR, \f(CW\*(C`grep\*(C'\fR followed by \f(CW\*(C`{\*(C'\fR if it starts \s-1BLOCK\s0 or hash ref.SpWhen 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'\fRstarts a \s-1BLOCK\s0 or a hash reference. If it guesses wrong, it will reporta syntax error near the \f(CW\*(C`}\*(C'\fR and the missing (or unexpected) comma..SpUse unary \f(CW\*(C`+\*(C'\fR before \f(CW\*(C`{\*(C'\fR on a hash reference, and unary \f(CW\*(C`+\*(C'\fR appliedto the first thing in a \s-1BLOCK\s0 (after \f(CW\*(C`{\*(C'\fR), for perl to guess right allthe time. (See \*(L"map\*(R" in perlfunc.).Sh "Numerical Traps".IX Subsection "Numerical Traps"Perl4\-to\-Perl5 traps having to do with numerical operators,operands, or output from same..IP "\(bu" 5Formatted output and significant digits.SpFormatted output and significant digits.  In general, Perl 5tries to be more precise.  For example, on a Solaris Sparc:.Sp.Vb 2\&    print 7.373504 \- 0, "\en";\&    printf "%20.18f\en", 7.373504 \- 0;\&\&    # Perl4 prints:\&    7.3750399999999996141\&    7.375039999999999614\&\&    # Perl5 prints:\&    7.373504\&    7.375039999999999614.Ve.SpNotice how the first result looks better in Perl 5..SpYour results may vary, since your floating point formatting routinesand even floating point format may be slightly different..IP "\(bu" 5Auto-increment operator over signed int limit deleted.SpThis specific item has been deleted.  It demonstrated how the auto-incrementoperator would not catch when a number went over the signed int limit.  Fixedin version 5.003_04.  But always be wary when using large integers.If in doubt:.Sp.Vb 1\&   use Math::BigInt;.Ve.IP "\(bu" 5Assignment of return values from numeric equality tests doesn't work.SpAssignment of return values from numeric equality testsdoes not work in perl5 when the test evaluates to false (0).Logical tests now return a null, instead of 0.Sp.Vb 2\&    $p = ($test == 1);\&    print $p,"\en";\&\&    # perl4 prints: 0\&    # perl5 prints:.Ve.SpAlso see \*(L"//, etc.\*(R"\*(L" in \*(R"General Regular Expression Traps using sfor another example of this new feature....IP "\(bu" 5Bitwise string ops.SpWhen bitwise operators which can operate upon either numbers orstrings (\f(CW\*(C`& | ^ ~\*(C'\fR) are given only strings as arguments, perl4 wouldtreat the operands as bitstrings so long as the program contained a callto the \f(CW\*(C`vec()\*(C'\fR function. perl5 treats the string operands as bitstrings.(See \*(L"Bitwise String Operators\*(R" in perlop for more details.).Sp.Vb 6\&    $fred = "10";\&    $barney = "12";\&    $betty = $fred & $barney;\&    print "$betty\en";\&    # Uncomment the next line to change perl4\*(Aqs behavior\&    # ($dummy) = vec("dummy", 0, 0);\&\&    # Perl4 prints:\&    8\&\&    # Perl5 prints:\&    10\&\&    # If vec() is used anywhere in the program, both print:\&    10.Ve.Sh "General data type traps".IX Subsection "General data type traps"Perl4\-to\-Perl5 traps involving most data-types, and their usagewithin certain expressions and/or context..IP "\(bu" 5Negative array subscripts now count from the end of array.SpNegative array subscripts now count from the end of the array..Sp.Vb 2\&    @a = (1, 2, 3, 4, 5);\&    print "The third element of the array is $a[3] also expressed as $a[\-2] \en";\&\&    # perl4 prints: The third element of the array is 4 also expressed as\&    # perl5 prints: The third element of the array is 4 also expressed as 4.Ve.IP "\(bu" 5Setting \f(CW$#array\fR lower now discards array elements.SpSetting \f(CW$#array\fR lower now discards array elements, and makes themimpossible to recover..Sp.Vb 6\&    @a = (a,b,c,d,e);\&    print "Before: ",join(\*(Aq\*(Aq,@a);\&    $#a =1;\&    print ", After: ",join(\*(Aq\*(Aq,@a);\&    $#a =3;\&    print ", Recovered: ",join(\*(Aq\*(Aq,@a),"\en";\&\&    # perl4 prints: Before: abcde, After: ab, Recovered: abcd\&    # perl5 prints: Before: abcde, After: ab, Recovered: ab.Ve.IP "\(bu" 5Hashes get defined before use.SpHashes get defined before use.Sp.Vb 4\&    local($s,@a,%h);\&    die "scalar \e$s defined" if defined($s);\&    die "array \e@a defined" if defined(@a);\&    die "hash \e%h defined" if defined(%h);\&\&    # perl4 prints:\&    # perl5 dies: hash %h defined.Ve.SpPerl will now generate a warning when it sees defined(@a) anddefined(%h)..IP "\(bu" 5Glob assignment from localized variable to variable.Spglob assignment from variable to variable will fail if the assignedvariable is localized subsequent to the assignment.Sp

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -