Website hosting service by Active-Venture.com
  

 Back to Index

Discontinuance, Deprecation, and BugFix traps

Anything that has been discontinued, deprecated, or fixed as a bug from perl4.

* Discontinuance

Symbols starting with "_" are no longer forced into package main, except for $_ itself (and @_, etc.).

 
    package test;
    $_legacy = 1;

    package main;
    print "\$_legacy is ",$_legacy,"\n";

    # perl4 prints: $_legacy is 1
    # perl5 prints: $_legacy is  

* Deprecation

Double-colon is now a valid package separator in a variable name. Thus these behave differently in perl4 vs. perl5, because the packages don't exist.

 
    $a=1;$b=2;$c=3;$var=4;
    print "$a::$b::$c ";
    print "$var::abc::xyz\n";

    # perl4 prints: 1::2::3 4::abc::xyz
    # perl5 prints: 3  

Given that :: is now the preferred package delimiter, it is debatable whether this should be classed as a bug or not. (The older package delimiter, ' ,is used here)

 
    $x = 10 ;
    print "x=${'x}\n" ;

    # perl4 prints: x=10
    # perl5 prints: Can't find string terminator "'" anywhere before EOF  

You can avoid this problem, and remain compatible with perl4, if you always explicitly include the package name:

 
    $x = 10 ;
    print "x=${main'x}\n" ;  

Also see precedence traps, for parsing $:.

* BugFix

The second and third arguments of splice() are now evaluated in scalar context (as the Camel says) rather than list context.

 
    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(' ',@a2),"\n";

    # perl4 prints: a b
    # perl5 prints: c d e  

* Discontinuance

You can't do a goto into a block that is optimized away. Darn.

 
    goto marker1;

    for(1){
    marker1:
        print "Here I is!\n";
    }

    # perl4 prints: Here I is!
    # perl5 errors: Can't "goto" into the middle of a foreach loop  

* Discontinuance

It is no longer syntactically legal to use whitespace as the name of a variable, or as a delimiter for any kind of quote construct. Double darn.

 
    $a = ("foo bar");
    $b = q baz ;
    print "a is $a, b is $b\n";

    # perl4 prints: a is foo bar, b is baz
    # perl5 errors: Bareword found where operator expected  

* Discontinuance

The archaic while/if BLOCK BLOCK syntax is no longer supported.

 
    if { 1 } {
        print "True!";
    }
    else {
        print "False!";
    }

    # perl4 prints: True!
    # perl5 errors: syntax error at test.pl line 1, near "if {"  

* BugFix

The ** operator now binds more tightly than unary minus. It was documented to work this way before, but didn't.

 
    print -4**2,"\n";

    # perl4 prints: 16
    # perl5 prints: -16  

* Discontinuance

The meaning of foreach{} has changed slightly when it is iterating over a list which is not an array. This used to assign the list to a temporary array, but no longer does so (for efficiency). This means that you'll now be iterating over the actual values, not over copies of the values. Modifications to the loop variable can change the original values.

 
    @list = ('ab','abc','bcd','def');
    foreach $var (grep(/ab/,@list)){
        $var = 1;
    }
    print (join(':',@list));

    # perl4 prints: ab:abc:bcd:def
    # perl5 prints: 1:1:bcd:def  

To retain Perl4 semantics you need to assign your list explicitly to a temporary array and then iterate over that. For example, you might need to change

 
    foreach $var (grep(/ab/,@list)){  

to

 
    foreach $var (@tmp = grep(/ab/,@list)){  

Otherwise changing $var will clobber the values of @list. (This most often happens when you use $_ for the loop variable, and call subroutines in the loop that don't properly localize $_.)

* Discontinuance

split with no arguments now behaves like split ' ' (which doesn't return an initial null field if $_ starts with whitespace), it used to behave like split /\s+/ (which does).

 
    $_ = ' hi mom';
    print join(':', split);

    # perl4 prints: :hi:mom
    # perl5 prints: hi:mom  

* BugFix

Perl 4 would ignore any text which was attached to an -e switch, always taking the code snippet from the following arg. Additionally, it would silently accept an -e switch without a following arg. Both of these behaviors have been fixed.

 
    perl -e'print "attached to -e"' 'print "separate arg"'

    # perl4 prints: separate arg
    # perl5 prints: attached to -e

    perl -e

    # perl4 prints:
    # perl5 dies: No code specified for -e.  

* Discontinuance

In Perl 4 the return value of push was undocumented, but it was actually the last value being pushed onto the target list. In Perl 5 the return value of push is documented, but has changed, it is the number of elements in the resulting list.

 
    @x = ('existing');
    print push(@x, 'first new', 'second new');

    # perl4 prints: second new
    # perl5 prints: 3  

* Deprecation
Some error messages will be different.
* Discontinuance
In Perl 4, if in list context the delimiters to the first argument of split() were ??, the result would be placed in @_ as well as being returned. Perl 5 has more respect for your subroutine arguments.
* Discontinuance
Some bugs may have been inadvertently removed. :-)

 

 

 

Domain name registration service & domain search - 
Register cheap domain name from $7.95 and enjoy free domain services 
 

Cheap domain name search service -
Domain name services at just
$8.95/year only
 

Register domain name -
Buy domain name registration and cheap domain transfer at low, affordable price.

© 2002-2004 Active-Venture.com Web Site Hosting Service

 

[ The generation of random numbers is too important to be left to chance.   ]

 

 
 
 

Disclaimer: This documentation is provided only for the benefits of our web hosting customers.
For authoritative source of the documentation, please refer to http://www.perldoc.com