Keep It Simple, Stupid | |
PerlMonks |
Re: On References to the Unnamedby mstone (Deacon) |
on Mar 16, 2005 at 19:48 UTC ( [id://440114]=note: print w/replies, xml ) | Need Help?? |
You could always use a simplified version of the trick from Glob.pm:
It does use a name to create the variable, but then deletes that name from the symbol table, which arguably results in an anonymous scalar. In an object constructor, it would looks like so:
or you can factor the ref code out into a separate function and just use:
By tweaking the specific kind of ref you create in anon_ref(), you can make it return scalars, lists, hashes, or entire globs. Most of the File:: classes use anonymous globs to store their filehandles, in fact..
In Section
Meditations
|
|