This code I constructed last night while I was chatting with you in the CB shows that even though you can tie %SIG, the "real" setting is still leaking through somewhere, and is the only one that has an effect:
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);
When executed, you get:
blessing MyTie=HASH(0x80d9290) MyTie=HASH(0x80d9290) is storing CODE(0x80d91e8) in ALRM bing! calling destroy on MyTie=HASH(0x80d9290)
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.

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:

blessing MyTie=HASH(0x80d92ec) MyTie=HASH(0x80d92ec) is storing CODE(0x80d2c30) in ALRM Alarm clock
which shows again that the tieing of %SIG is apparently not consulted.

Oh well.

-- Randal L. Schwartz, Perl hacker


In reply to Re: Tied %SIG by merlyn
in thread Tied %SIG by bbfu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.