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

📄 perltrap.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 4 页
字号:
.Vb 4\&    @a = ("This is Perl 4");\&    *b = *a;\&    local(@a);\&    print @b,"\en";\&\&    # perl4 prints: This is Perl 4\&    # perl5 prints:.Ve.IP "\(bu" 5Assigning \f(CW\*(C`undef\*(C'\fR to glob.SpAssigning \f(CW\*(C`undef\*(C'\fR to a glob has no effect in Perl 5.   In Perl 4it undefines the associated scalar (but may have other side effectsincluding SEGVs). Perl 5 will also warn if \f(CW\*(C`undef\*(C'\fR is assigned to atypeglob. (Note that assigning \f(CW\*(C`undef\*(C'\fR to a typeglob is differentthan calling the \f(CW\*(C`undef\*(C'\fR function on a typeglob (\f(CW\*(C`undef *foo\*(C'\fR), whichhas quite a few effects..Sp.Vb 3\&    $foo = "bar";\&    *foo = undef;\&    print $foo;\&\&    # perl4 prints:\&    # perl4 warns: "Use of uninitialized variable" if using \-w\&    # perl5 prints: bar\&    # perl5 warns: "Undefined value assigned to typeglob" if using \-w.Ve.IP "\(bu" 5Changes in unary negation (of strings).SpChanges in unary negation (of strings)This change effects both the return value and what itdoes to auto(magic)increment..Sp.Vb 4\&    $x = "aaa";\&    print ++$x," : ";\&    print \-$x," : ";\&    print ++$x,"\en";\&\&    # perl4 prints: aab : \-0 : 1\&    # perl5 prints: aab : \-aab : aac.Ve.IP "\(bu" 5Modifying of constants prohibited.Spperl 4 lets you modify constants:.Sp.Vb 10\&    $foo = "x";\&    &mod($foo);\&    for ($x = 0; $x < 3; $x++) {\&        &mod("a");\&    }\&    sub mod {\&        print "before: $_[0]";\&        $_[0] = "m";\&        print "  after: $_[0]\en";\&    }\&\&    # perl4:\&    # before: x  after: m\&    # before: a  after: m\&    # before: m  after: m\&    # before: m  after: m\&\&    # Perl5:\&    # before: x  after: m\&    # Modification of a read\-only value attempted at foo.pl line 12.\&    # before: a.Ve.IP "\(bu" 5\&\f(CW\*(C`defined $var\*(C'\fR behavior changed.SpThe behavior is slightly different for:.Sp.Vb 1\&    print "$x", defined $x\&\&    # perl 4: 1\&    # perl 5: <no output, $x is not called into existence>.Ve.IP "\(bu" 5Variable Suicide.SpVariable suicide behavior is more consistent under Perl 5.Perl5 exhibits the same behavior for hashes and scalars,that perl4 exhibits for only scalars..Sp.Vb 4\&    $aGlobal{ "aKey" } = "global value";\&    print "MAIN:", $aGlobal{"aKey"}, "\en";\&    $GlobalLevel = 0;\&    &test( *aGlobal );\&\&    sub test {\&        local( *theArgument ) = @_;\&        local( %aNewLocal ); # perl 4 != 5.001l,m\&        $aNewLocal{"aKey"} = "this should never appear";\&        print "SUB: ", $theArgument{"aKey"}, "\en";\&        $aNewLocal{"aKey"} = "level $GlobalLevel";   # what should print\&        $GlobalLevel++;\&        if( $GlobalLevel<4 ) {\&            &test( *aNewLocal );\&        }\&    }\&\&    # Perl4:\&    # MAIN:global value\&    # SUB: global value\&    # SUB: level 0\&    # SUB: level 1\&    # SUB: level 2\&\&    # Perl5:\&    # MAIN:global value\&    # SUB: global value\&    # SUB: this should never appear\&    # SUB: this should never appear\&    # SUB: this should never appear.Ve.Sh "Context Traps \- scalar, list contexts".IX Subsection "Context Traps - scalar, list contexts".IP "\(bu" 5Elements of argument lists for formats evaluated in list context.SpThe elements of argument lists for formats are now evaluated in listcontext.  This means you can interpolate list values now..Sp.Vb 6\&    @fmt = ("foo","bar","baz");\&    format STDOUT=\&    @<<<<< @||||| @>>>>>\&    @fmt;\&    .\&    write;\&\&    # perl4 errors:  Please use commas to separate fields in file\&    # perl5 prints: foo     bar      baz.Ve.IP "\(bu" 5\&\f(CW\*(C`caller()\*(C'\fR returns false value in scalar context if no caller present.SpThe \f(CW\*(C`caller()\*(C'\fR function now returns a false value in a scalar contextif there is no caller.  This lets library files determine if they'rebeing required..Sp.Vb 1\&    caller() ? (print "You rang?\en") : (print "Got a 0\en");\&\&    # perl4 errors: There is no caller\&    # perl5 prints: Got a 0.Ve.IP "\(bu" 5Comma operator in scalar context gives scalar context to args.SpThe comma operator in a scalar context is now guaranteed to give ascalar context to its arguments..Sp.Vb 3\&    @y= (\*(Aqa\*(Aq,\*(Aqb\*(Aq,\*(Aqc\*(Aq);\&    $x = (1, 2, @y);\&    print "x = $x\en";\&\&    # Perl4 prints:  x = c   # Thinks list context interpolates list\&    # Perl5 prints:  x = 3   # Knows scalar uses length of list.Ve.IP "\(bu" 5\&\f(CW\*(C`sprintf()\*(C'\fR prototyped as \f(CW\*(C`($;@)\*(C'\fR.Sp\&\f(CW\*(C`sprintf()\*(C'\fR is prototyped as ($;@), so its first argument is given scalarcontext. Thus, if passed an array, it will probably not do what you want,unlike Perl 4:.Sp.Vb 3\&    @z = (\*(Aq%s%s\*(Aq, \*(Aqfoo\*(Aq, \*(Aqbar\*(Aq);\&    $x = sprintf(@z);\&    print $x;\&\&    # perl4 prints: foobar\&    # perl5 prints: 3.Ve.Sp\&\f(CW\*(C`printf()\*(C'\fR works the same as it did in Perl 4, though:.Sp.Vb 2\&    @z = (\*(Aq%s%s\*(Aq, \*(Aqfoo\*(Aq, \*(Aqbar\*(Aq);\&    printf STDOUT (@z);\&\&    # perl4 prints: foobar\&    # perl5 prints: foobar.Ve.Sh "Precedence Traps".IX Subsection "Precedence Traps"Perl4\-to\-Perl5 traps involving precedence order..PPPerl 4 has almost the same precedence rules as Perl 5 for the operatorsthat they both have.  Perl 4 however, seems to have had someinconsistencies that made the behavior differ from what was documented..IP "\(bu" 5\&\s-1LHS\s0 vs. \s-1RHS\s0 of any assignment operator.Sp\&\s-1LHS\s0 vs. \s-1RHS\s0 of any assignment operator.  \s-1LHS\s0 is evaluated firstin perl4, second in perl5; this can affect the relationshipbetween side-effects in sub-expressions..Sp.Vb 3\&    @arr = ( \*(Aqleft\*(Aq, \*(Aqright\*(Aq );\&    $a{shift @arr} = shift @arr;\&    print join( \*(Aq \*(Aq, keys %a );\&\&    # perl4 prints: left\&    # perl5 prints: right.Ve.IP "\(bu" 5Semantic errors introduced due to precedence.SpThese are now semantic errors because of precedence:.Sp.Vb 6\&    @list = (1,2,3,4,5);\&    %map = ("a",1,"b",2,"c",3,"d",4);\&    $n = shift @list + 2;   # first item in list plus 2\&    print "n is $n, ";\&    $m = keys %map + 2;     # number of items in hash plus 2\&    print "m is $m\en";\&\&    # perl4 prints: n is 3, m is 6\&    # perl5 errors and fails to compile.Ve.IP "\(bu" 5Precedence of assignment operators same as the precedence of assignment.SpThe precedence of assignment operators is now the same as the precedenceof assignment.  Perl 4 mistakenly gave them the precedence of the associatedoperator.  So you now must parenthesize them in expressions like.Sp.Vb 1\&    /foo/ ? ($a += 2) : ($a \-= 2);.Ve.SpOtherwise.Sp.Vb 1\&    /foo/ ? $a += 2 : $a \-= 2.Ve.Spwould be erroneously parsed as.Sp.Vb 1\&    (/foo/ ? $a += 2 : $a) \-= 2;.Ve.SpOn the other hand,.Sp.Vb 1\&    $a += /foo/ ? 1 : 2;.Ve.Spnow works as a C programmer would expect..IP "\(bu" 5\&\f(CW\*(C`open\*(C'\fR requires parentheses around filehandle.Sp.Vb 1\&    open FOO || die;.Ve.Spis now incorrect.  You need parentheses around the filehandle.Otherwise, perl5 leaves the statement as its default precedence:.Sp.Vb 1\&    open(FOO || die);\&\&    # perl4 opens or dies\&    # perl5 opens FOO, dying only if \*(AqFOO\*(Aq is false, i.e. never.Ve.IP "\(bu" 5\&\f(CW$:\fR precedence over \f(CW$::\fR gone.Spperl4 gives the special variable, \f(CW$:\fR precedence, where perl5treats \f(CW$::\fR as main \f(CW\*(C`package\*(C'\fR.Sp.Vb 1\&    $a = "x"; print "$::a";\&\&    # perl 4 prints: \-:a\&    # perl 5 prints: x.Ve.IP "\(bu" 5Precedence of file test operators documented.Spperl4 had buggy precedence for the file test operators vis-a-visthe assignment operators.  Thus, although the precedence tablefor perl4 leads one to believe \f(CW\*(C`\-e $foo .= "q"\*(C'\fR should parse as\&\f(CW\*(C`((\-e $foo) .= "q")\*(C'\fR, it actually parses as \f(CW\*(C`(\-e ($foo .= "q"))\*(C'\fR.In perl5, the precedence is as documented..Sp.Vb 1\&    \-e $foo .= "q"\&\&    # perl4 prints: no output\&    # perl5 prints: Can\*(Aqt modify \-e in concatenation.Ve.IP "\(bu" 5\&\f(CW\*(C`keys\*(C'\fR, \f(CW\*(C`each\*(C'\fR, \f(CW\*(C`values\*(C'\fR are regular named unary operators.SpIn perl4, \fIkeys()\fR, \fIeach()\fR and \fIvalues()\fR were special high-precedence operatorsthat operated on a single hash, but in perl5, they are regular named unaryoperators.  As documented, named unary operators have lower precedencethan the arithmetic and concatenation operators \f(CW\*(C`+ \- .\*(C'\fR, but the perl4variants of these operators actually bind tighter than \f(CW\*(C`+ \- .\*(C'\fR.Thus, for:.Sp.Vb 2\&    %foo = 1..10;\&    print keys %foo \- 1\&\&    # perl4 prints: 4\&    # perl5 prints: Type of arg 1 to keys must be hash (not subtraction).Ve.SpThe perl4 behavior was probably more useful, if less consistent..Sh "General Regular Expression Traps using s///, etc.".IX Subsection "General Regular Expression Traps using s///, etc."All types of \s-1RE\s0 traps..IP "\(bu" 5\&\f(CW\*(C`s\*(Aq$lhs\*(Aq$rhs\*(Aq\*(C'\fR interpolates on either side.Sp\&\f(CW\*(C`s\*(Aq$lhs\*(Aq$rhs\*(Aq\*(C'\fR now does no interpolation on either side.  It used tointerpolate \f(CW$lhs\fR but not \f(CW$rhs\fR.  (And still does not match a literal\&'$' in string).Sp.Vb 4\&    $a=1;$b=2;\&    $string = \*(Aq1 2 $a $b\*(Aq;\&    $string =~ s\*(Aq$a\*(Aq$b\*(Aq;\&    print $string,"\en";\&\&    # perl4 prints: $b 2 $a $b\&    # perl5 prints: 1 2 $a $b.Ve.IP "\(bu" 5\&\f(CW\*(C`m//g\*(C'\fR attaches its state to the searched string.Sp\&\f(CW\*(C`m//g\*(C'\fR now attaches its state to the searched string rather than theregular expression.  (Once the scope of a block is left for the sub, thestate of the searched string is lost).Sp.Vb 5\&    $_ = "ababab";\&    while(m/ab/g){\&        &doit("blah");\&    }\&    sub doit{local($_) = shift; print "Got $_ "}\&\&    # perl4 prints: Got blah Got blah Got blah Got blah\&    # perl5 prints: infinite loop blah....Ve.IP "\(bu" 5\&\f(CW\*(C`m//o\*(C'\fR used within an anonymous sub.SpCurrently, if you use the \f(CW\*(C`m//o\*(C'\fR qualifier on a regular expressionwithin an anonymous sub, \fIall\fR closures generated from that anonymoussub will use the regular expression as it was compiled when it was usedthe very first time in any such closure.  For instance, if you say.Sp.Vb 9\&    sub build_match {\&        my($left,$right) = @_;\&        return sub { $_[0] =~ /$left stuff $right/o; };\&    }\&    $good = build_match(\*(Aqfoo\*(Aq,\*(Aqbar\*(Aq);\&    $bad = build_match(\*(Aqbaz\*(Aq,\*(Aqblarch\*(Aq);\&    print $good\->(\*(Aqfoo stuff bar\*(Aq) ? "ok\en" : "not ok\en";\&    print $bad\->(\*(Aqbaz stuff blarch\*(Aq) ? "ok\en" : "not ok\en";\&    print $bad\->(\*(Aqfoo stuff bar\*(Aq) ? "not ok\en" : "ok\en";.Ve.SpFor most builds of Perl5, this will print:oknot oknot ok.Sp\&\fIbuild_match()\fR will always return a sub which matches the contents of\&\f(CW$left\fR and \f(CW$right\fR as they were the \fIfirst\fR time that \fIbuild_match()\fRwas called, not as they are in the current call..IP "\(bu" 5\&\f(CW$+\fR isn't set to whole match.SpIf no parentheses are used in a match, Perl4 sets \f(CW$+\fR tothe whole match, just like \f(CW$&\fR. Perl5 does not..Sp.Vb 2\&    "abcdef" =~ /b.*e/;\&    print "\e$+ = $+\en";\&\&    # perl4 prints: bcde\&    # perl5 prints:.Ve.IP "\(bu" 5Substitution now returns null string if it fails.Spsubstitution now returns the null string if it fails.Sp.Vb 3\&    $string = "test";\&    $value = ($string =~ s/foo//);\&    print $value, "\en";\&\&    # perl4 prints: 0\&    # perl5 prints:.Ve.SpAlso see \*(L"Numerical Traps\*(R" for another example of this new feature..IP "\(bu" 5\&\f(CW\*(C`s\`lhs\`rhs\`\*(C'\fR is now a normal substitution.Sp\&\f(CW\*(C`s\`lhs\`rhs\`\*(C'\fR (using backticks) is now a normal substitution, with nobacktick expansion.Sp.Vb 3\&    $string = "";

⌨️ 快捷键说明

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