pre-ramble:
Ive recently become quite enamoured with the idea of using anonymous typeglobs
as the underlying datastructure for objects.
While the only real-world use I have seen of this is in the IO::* suite
- I have came across several scenarios where having each of Perl's datatypes
fits quite nicely with the problem space at hand. As a quick example
now, wanting that structure to be tied to a socket/pipe/file is not wholly unlikely - but regardless, a typeglob fits perfectly.package nodeOfSomeKind; sub new { my $node = { refToParent => undef, hashParams => {}, arrayOfKids => [], }; return bless $node; }
package Globject; our %classes; sub new { my $class = shift; # keep it unique my $symbolname = $class . ++$classes{$class}; my $tGlob = \*{$symbolname}; delete $Globject::{$symbolname}; # kill the package global return bless($tGlob, $class); }
so, deleting the autovivified symbol table entry gets rid of the package global - but the symbol lives on in the blessed reference. Woah!
So this got my tiny mind whirring...
From the little I know, lexical variables dont get symbol table entries as they exist only on a "pad" - for the scope of whatever block they exist in. Fine. But within that block, are they still represented in the equivalent of a local temporary symbol?. That is, wherever Perl is keeping tabs on all my variables for this scope, does it model the same structure as the symbol table?
sub foo { my ($foo, @foo, %foo); # now, within this lexical scope, are these names related return $foo; }
I guess my question/meditation would be twofold -
(i) apart from the lexical bit, what does my() do (if anything) that is different
from Perl's normal way of creating variables?
(ii) blessed GLOB refs. Yay or Neigh?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: understanding my() and typeglobs
by Aristotle (Chancellor) on Mar 16, 2003 at 14:37 UTC | |
by Ctrl-z (Friar) on Mar 16, 2003 at 15:49 UTC | |
|
Re: understanding my() and typeglobs (perl6)
by tye (Sage) on Mar 17, 2003 at 02:14 UTC | |
by chromatic (Archbishop) on Mar 17, 2003 at 04:46 UTC | |
by Elian (Parson) on Mar 17, 2003 at 14:43 UTC | |
by Ctrl-z (Friar) on Mar 17, 2003 at 18:47 UTC | |
by Elian (Parson) on Mar 17, 2003 at 19:20 UTC | |
by Ctrl-z (Friar) on Mar 17, 2003 at 14:32 UTC | |
by diotalevi (Canon) on Mar 17, 2003 at 14:59 UTC | |
by Ctrl-z (Friar) on Mar 17, 2003 at 18:05 UTC |