How can I make a single reference that can be LEGALLY DEREFERENCED as a hash ref, array ref, AND a scalar ref, with the resulting operation tied to a class implementation?Probably the easiest thing is to use a glob:
The biggest drawback of this approach is that you can't bless the resulting $thing, because it isn't really a reference. But perhaps you don't care to do so.my $thing; { $thing = local *GLOB; } $$thing = 20; @$thing = (1,2,3); %$thing = ('apple'=>'red', 'banana'=>'yellow'); # or use $thing->[...] and $thing->{...} # or tie as usual: tie %$thing => Hashclass, ...; tie @$thing => Arrayclass, ...; tie $$thing => Scalarclass, ...;
Hope this helps.
--
Mark Dominus
Perl Paraphernalia
In reply to Re: I'm looking for some 'heavy magic'
by Dominus
in thread I'm looking for some 'heavy magic'
by dpmott
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |