Ok, first off a little comment about posting ettiquette. Please use <code> tags in the future. You apparently didnt notice that your code does not render the way it is typed but the code is unrunnable from a copy/paste.

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)

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)
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.)

BTW: here is a (more) minimal piece of code that demonstrates your bug, this is the kind of thing people would prefer to see:

package 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";
HTH

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

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.