Home
Search Perl pages
Subjects
By activity
Professions, Sciences, Humanities, Business, ...
User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...
Text Strings
Conversions, tests, processing, manipulation,...
Math
Integer, Floating point, Matrix, Statistics, Boolean, ...
Processing
Algorithms, Memory, Process control, Debugging, ...
Stored Data
Data storage, Integrity, Encryption, Compression, ...
Communications
Networks, protocols, Interprocess, Remote, Client Server, ...
Hard World Timing, Calendar and Clock, Audio, Video, Printer, Controls...
File System
Management, Filtering, File & Directory access, Viewers, ...
|
|
|
Variable "%s" may be unavailable
(W) An inner (nested) anonymous subroutine is inside a named
subroutine, and outside that is another subroutine; and the anonymous
(innermost) subroutine is referencing a lexical variable defined in the
outermost subroutine. For example:
sub outermost { my $a; sub middle { sub { $a } } }
If the anonymous subroutine is called or referenced (directly or
indirectly) from the outermost subroutine, it will share the variable as
you would expect. But if the anonymous subroutine is called or referenced
when the outermost subroutine is not active, it will see the value of the
shared variable as it was before and during the *first* call to the
outermost subroutine, which is probably not what you want.
In these circumstances, it is usually best to make the middle subroutine
anonymous, using the sub {} syntax. Perl has specific support for shared variables in nested anonymous
subroutines; a named subroutine in between interferes with this feature.
Variable "%s" will not stay shared
(W) An inner (nested) named subroutine is referencing a lexical variable defined in an outer
subroutine.
When the inner subroutine is called, it will probably see the value of the
outer subroutine's variable as it was before and during the *first* call to
the outer subroutine; in this case, after the first call to the outer
subroutine is complete, the inner and outer subroutines will no longer
share a common value for the variable. In other words, the variable will no
longer be shared.
Furthermore, if the outer subroutine is anonymous and references a lexical
variable outside itself, then the outer and inner subroutines will never share the given variable.
This problem can usually be solved by making the inner subroutine
anonymous, using the sub {} syntax. When inner anonymous subs that reference variables in outer
subroutines are called or referenced, they are automatically rebound to the
current values of such variables.
Source: what's new for perl5.004 Copyright: Larry Wall, et al. |
Next: Warning: something's wrong
Previous: Value of %s can be "0"; test with defined()
(Corrections, notes, and links courtesy of RocketAware.com)
Up to: PERL
Rapid-Links:
Search | About | Comments | Submit Path: RocketAware > Perl >
perldelta/Variable.htm
RocketAware.com is a service of Mib Software Copyright 2000, Forrest J. Cavalier III. All Rights Reserved. We welcome submissions and comments
|