Chas Owens wrote:
> On 4/6/06, John W. Krahn <[EMAIL PROTECTED]> wrote:
> snip
>>>use POSIX ":sys_wait_h";
>>>
>>>my $handler = sub {
>>>    my $pid;
>>>    while (($pid = waitpid(-1, &WNOHANG)) > 0) {
>>>        # do something with $pid
>>>    }
>>>    $SIG{CHLD} = $handler #reinstall the handler
>> 
>>When perl compiles this it will use $main::handler for the assignment.
> 
> Yes, it will.  And since $main::handler holds the anonymous subroutine
> that I want reinstalled that is good.

No, the lexical $handler holds the anonymous subroutine.

$ perl -e'
use Data::Dumper;

my $h = sub {  $a = $h  };

print Dumper $_ for $a, $h, $main::a, $main::h;
'
$VAR1 = undef;
$VAR1 = sub { "DUMMY" };
$VAR1 = undef;
$VAR1 = undef;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to