Richard Trahan <> wrote:
> Consider the following code:
>
> use strict;
> {
> my $x = 5;
> our $sr = sub { print "$x\n"; };
> }
> &$sr;
>
> This code gives a scope error, but if I remove 'use strict',
> it works ok.
>
> The 'our $sr' statement should make an entry in the SCALAR
> slot of *main::sr, right?
Right, the value is there.
You are having trouble _accessing_ that value though.
> What am I missing here?
All that "our" gets you is to make "use strict" shut up about using
short names rather than long names.
The "permission to use short names" is scoped, once outside that
scope, you must use the fully qualified package name again.
So:
&{$main::sr};
or
$main::sr->();
or, if you want to use the short name after the block, ask for that
with an
our $sr;
after the block.
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas