7.7 Perl 5.004

Previous Table of Contents Next

7.7 Perl 5.004

Allowed my to appear inside control structures, so that while (my $x = pop), for instance, would create a new lexical variable scoped just to the while loop. Added the use of the arrow operator for dereferencing subroutine references, tied filehandles, and the UNIVERSAL methods can() and isa(). The regular expression anchor constant pragma and CGI.pm were added to the core modules.

7.7.1 Upgrading to Perl 5.004

Where a for, foreach, while, or until loop uses a lexical loop variable that is not used or should not be used elsewhere in the program, you can ensure it is isolated by embedding it in the loop statement:

for (my $i = 0; $i < 10; $i++) { ... }

foreach my $rocker (@Beatles, @Stones) { ... }

while (my $soda = pop) { ... }

If the program defines de facto constants using argumentless subroutine prototypes, for example:

sub avogadro () { 6.023E23 }

then they can be replaced by calls to the constant pragma:

use constant avogadro => 6.023E23;

if you find that more appealing.

It is unlikely that you would rapidly recognize a regular expression that would benefit from the \G.

    Previous Table of Contents Next
    © 2000- NIV