Приглашаем посетить
Островский (ostrovskiy.lit-info.ru)

7.9 Perl 5.6.0

Previous Table of Contents Next

7.9 Perl 5.6.0

This version of Perl was longer in the making than most of the others, but that was because so much was added. Therefore the version number format was altered to denote the importance of this update. A number of people did not recommend this version due to certain bugs. Others were unaffected and wondered what the fuss was about.

Lexical warnings (use warnings) were added, as was the initial support for Unicode (use bytes/use utf8). The our declaration made its first appearance. User-defined attributes showed up, and replaced the limited attrs pragma. Version strings were added, amid some controversy: Numbers beginning with v, or with more than one period in them, were automatically converted to a packed binary form.

open() came in for some enhancements: If the filehandle was an undefined variable, open() would store the filehandle there, so you could say open my $fh,..., and have a lexically scoped filehandle that would automatically be closed on being garbage collected. The three-argument form of open() appeared, as did binary literals and lvalue subroutines. You could now call exists() on subroutines and array elements, and delete() on array elements.

7.9.1 Upgrading to Perl 5.6.0

Remove the -w command-line flag and add the use warnings pragma in every file; look for where the $^W special variable is set to 0 and change that to a no warnings pragma for the appropriate warning class.

Replace use vars with our and look to see whether it can be placed in a small lexical scope. Use scalar variable filehandles (e.g., open($fh, ...)) and declare them in the smallest scope necessary; you can then remove a close() statement at the end of that scope if you do not need to check its return status. Convert open() statements to the three-argument form, especially if they are preceded by code that attempts to tell whether the filename argument might contain shell metacharacters.[2]

[2] Some rather clever code might rely on the magical behavior of open(), assuming that it is used by experts who are familiar with its special abilities. If the code was written by an expert, there is a small chance this might be happening.

Lvalue subroutines are still experimental. It would be unwise to go looking for opportunities to insert them into legacy code.

    Previous Table of Contents Next