develooper Front page | perl.perl5.porters | Postings from June 2004

non destructive ties

Thread Next
From:
Edward Peschko
Date:
June 25, 2004 02:25
Subject:
non destructive ties
Message ID:
20040625022625.GA3087@mdssdev05
hey all,

I noticed when doing a tie, namely:

tie(%hash, 'Whatever::Package');

that I destroy whatever is in the hash - due to TIEHASH only taking the second parameter
as an argument, ie:

sub TIEHASH
{
	bless {}, $_[0];
}

Is there any way to bless the reference without destroying the data inside of it?
Its sort of annoying to have to duplex the hash via: 

%oldhash = %hash;
tie(%hash, 'Whatever::Package');
%hash = %oldhash;

I guess this works, but its pretty clumsy. Why doesn't TIEHASH simply reproduce the 
arguments, such that $_[0] == %hash and $_[1] == 'Whatever::Package'?

Ed

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About