Eyck has asked for the wisdom of the Perl Monks concerning the following question:

I've been bitten by a side effect, here's example code from documentation of Net::SSLeay::Handle:

my $socket \*S1; if ($scheme eq "https") { tie(*S2, "Net::SSLeay::Handle", $socket); $socket = \*S2; }

This works OK, unfortunatelly I used it in a library inside object, so when you brought two life multiple such objects

for $sth (@sth) { my $object=new STH; $objects{$sth}=$object; };

the whole shebang failed miserably (the last invocation of $object hides every other SSLeay::Handle (there is only one \*S2)

Now I'm trying to fix the code, here's my attempt which seems to work at the moment:

{my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket);$so +cket = \*$io;}; { my $io=new IO::Handle; tie(*$io, "Net::SSLeay::Handle", $socket); $socket = \*$io; };

AFAIK this works because every $io=new IO::Handle generates unique identifier, so my code above might be replaced with

$global-net-ssleay-counter++; tie(*$global.....
and it would still work, and wouldn't depend on chance (I hope two IO::Handle->new()don't get the same identifier).

What is the proper solution to this? How should I use Net::SSLeay::Handle?