in reply to Tied %SIG
When executed, you get:Buffers Files Tools Edit Search Perl Help + #!/usr/bin/perl -w use strict; $|++; { package MyTie; sub TIEHASH { my $class = shift; my %value; my $self = { value => \%value }; bless $self, $class; warn "blessing $self\n"; # $self->STORE("ALRM", sub { warn "BONG" }); $self; } sub FETCH { my $self = shift; my $key = shift; my $value = $self->{value}->{$key}; warn "$self is fetching $key as $value\n"; $value; } sub STORE { my $self = shift; my $key = shift; my $newvalue = shift; warn "$self is storing $newvalue in $key\n"; $self->{value}->{$key} = $newvalue; } sub DELETE { my $self = shift; my $key = shift; warn "$self is deleting $key\n"; delete $self->{value}->{$key}; } sub CLEAR { my $self = shift; warn "clearing $self\n"; %{$self->{value}} = (); } sub EXISTS { my $self = shift; my $key = shift; warn "checking existance of $key in $self\n"; exists $self->{value}->{$key}; } sub FIRSTKEY { my $self = shift; warn "calling firstkey on $self\n"; my $toss = keys %{$self->{value}}; each %{$self->{value}}; } sub NEXTKEY { my $self = shift; warn "calling nextkey on $self\n"; each %{$self->{value}}; } sub DESTROY { my $self = shift; warn "calling destroy on $self\n"; $self->SUPER::DESTROY; } } tie %::SIG, MyTie::; $SIG{ALRM} = sub { warn "bing!\n" }; alarm(1); select(undef, undef, undef, 3);
which shows clearly that the setting of $SIG{ARLM} is both affecting the underlying signal handler and calling the tie STORE operation, but notice at the alarm hit, no corresponding FETCH is called, so the value currently in the private hash would have no effect as it is not consulted.blessing MyTie=HASH(0x80d9290) MyTie=HASH(0x80d9290) is storing CODE(0x80d91e8) in ALRM bing! calling destroy on MyTie=HASH(0x80d9290)
Now, uncomment the commented STORE in the early part of the program, and comment out the explicit setting of $SIG{ALRM} at the end, and you get:
which shows again that the tieing of %SIG is apparently not consulted.blessing MyTie=HASH(0x80d92ec) MyTie=HASH(0x80d92ec) is storing CODE(0x80d2c30) in ALRM Alarm clock
Oh well.
-- Randal L. Schwartz, Perl hacker
|
---|