in reply to Autovivifying XS routine
When you needed an array ref, you used a function. When you needed a hash ref, you used a scalar. If that's all you want, there's no problem. Just have the function always return an array, and have the scalar always contain a hash reference.
Perhaps what you really what is
@{ $gimme_a_ref } = ( 1, 2, 3 ); $gimme_a_ref->{haha} = 'hihi';
or
@{ gimme_a_ref() } = ( 1, 2, 3 ); gimme_a_ref()->{haha} = 'hihi';
In other words, perhaps what you really want is to return different references based on the type of reference needed. I don't know if there's a term for that, but it's not auto-vivification.
In the case of first syntax I presented, operator overloading should do the trick. Check @{} and %{} in overload.
In the case of second syntax I presented, you could simply return an object with @{} and %{} overloaded (like for the first syntax), or you could mimic WANT. (I hope I have the module name right, I don't have access to CPAN to check.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Autovivifying XS routine
by Anno (Deacon) on Jun 01, 2007 at 15:01 UTC |