in reply to weak-reference set internally
I used $copy to make $bar and $baz strong again; "isweak" from Scalar::Util to test if the refs were weak. If they're weak, they'll come back true. If they're not weak, they'll come back false; also, I checked the refcount with Scalar::Util::Refcount to double-check what was happening.#!/usr/bin/perl use strict; use warnings; use Scalar::Util qw(weaken isweak); use Scalar::Util::Refcount; my $foo; my $bar; my $baz; my $ref1 = \$foo; weaken($ref1); print my $weak = isweak($ref1), "\n"; print refcount($foo), "\n"; my $ref2 = \$bar; weaken($ref2); print $weak = isweak($ref2), "\n"; print refcount($baz), "\n"; my $ref3 = \$baz; weaken($ref3); print $weak = isweak($ref3), "\n"; print refcount($baz), "\n\n"; my $copy1 = $ref2; $weak = isweak($copy1); my $copy2 = $ref3; $weak = isweak($copy2), "\n";
Update: Fixed some omissions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: weak-reference set internally
by Cagao (Monk) on Sep 30, 2010 at 22:41 UTC |