Second, please in the future provide code THAT ILLUSTRATES the bug. Don't write a command line parser that we then have to figure out how to use before we can see the problem. I deleted just about the entire main because for me it was useless. Also, i think that if you had done a little more rigourous searching you would have seen (assuming you are on 5.6.1) that you have found a bug, but it isnt the one you think. (see the code at the bottom that generated this)
So clearly the %$H is indeed tied after the CLEAR. However it appears that for some reason it and %h itself ar not tied _during_ the scope of the CLEAR itself. Presumably this shouldn't be a problem and is probably related to the implementation of the TIE internally (there are a number of known bugs in the TIE implementation, this would be just one more. Nevertheless It Will get reported.)Ref $H: HASH(0x1c19d50) Before STORE: %$H - %$H - Toy::Hash=HASH(0x1c199a4) %h -Toy::Hash=H +ASH(0x1c199a4) in Toy::Hash::STORE, tied(%$H) is Toy::Hash=HASH(0x1c199a4) Ref:(HASH( +0x1c19d50)) in Toy::Hash::STORE, tied(%h) is Toy::Hash=HASH(0x1c199a4) After STORE: %$H - Toy::Hash=HASH(0x1c199a4) %h -Toy::Hash=HASH(0x +1c199a4) Ref $H: HASH(0x1c19d50) Before CLEAR: %$H - Toy::Hash=HASH(0x1c199a4) %h -Toy::Hash=HASH(0x +1c199a4) in Toy::Hash::CLEAR, tied(%$H) is '' Ref:(HASH(0x1c19d50)) in Toy::Hash::CLEAR, tied(%h) is '' After CLEAR: %$H - Toy::Hash=HASH(0x1c199a4) %h -Toy::Hash=HASH(0x +1c199a4) Ref $H: HASH(0x1c19d50)
BTW: here is a (more) minimal piece of code that demonstrates your bug, this is the kind of thing people would prefer to see:
HTHpackage Toy::Hash; use strict; use warnings; sub TIEHASH { my $class = shift; return bless { values => { @_ } }, $class; } sub STORE { my ( $self, $key, $value ) = @_; ::is_H_tied(); $self->{values}{$key} = $value; } sub CLEAR { my ( $self ) = @_; ::is_H_tied(); %{ $self->{values} } = (); } package main; use strict; our $H; my @k = ( 1..30 ); tie( my %h, 'Toy::Hash', map { $_, $_ * $_ } @k ); $H = \%h; sub is_H_tied { my $m = ( caller( 1 ) )[3]; print "in $m, tied(\%\$H) is ". (tied( %{$::H} ) || "''"). " Ref:($H +)\n"; print "in $m, tied(\%h) is ". (tied( %h ) || "''"). "\n"; } print "Ref \$H: $H\n\n"; print "Before STORE: %\$H - %\$H - ",tied(%$H) . "\t\%h -" . tied(%h). + "\n"; $H->{foo}="bar"; print "After STORE: %\$H - ",tied(%$H) . "\t\%h -" . tied(%h). "\n\n" +; print "Ref \$H: $H\n\n"; print "Before CLEAR: %\$H - ",tied(%$H) . "\t\%h -" . tied(%h). "\n"; %$H=(); print "After CLEAR: %\$H - ",tied(%$H) . "\t\%h -" . tied(%h). "\n\n" +; print "Ref \$H: $H\n";
UPDATE:This matter has been posted to P5P.
--- demerphq
my friends call me, usually because I'm late....
In reply to Re: Where's my tie ?
by demerphq
in thread Where's my tie ?
by philou
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |