in reply to Re: Re: Re: Sorting strings
in thread Sorting strings
Dynamic variables are package scoped, which means that such a variable (unless local()ized, which we may get to later) is available and shared throughout the *whole* package. These variables are entered into something called a 'pad' or more formally the package symbol table. This table is essentially a hash where the names (without type symbols $ % @ &) are the keys, and the values are these things called typeglobs (which are accessed through the * type symbol) this hash is reffered to inside a package as %:: and outside as %PACKAGE::. A typeglob is essentially a wrapper around the various types that a given name represents. Or in other terms a typeglob is a bundle of all of the dynamic variables that have a given name.This can be seen heremy $lexical="Value"; our $dynamic="Value";
If you run it you will see that accessing any variable type with the name Other_Variable really access the equivelent type with the name Variable (and vice versa, they are aliased to each other.) All with ONE assignment.#assuming warnings and strict our $Variable="Variable"; our %Variable=(hash_key=>"Variable"); our @Variable=split(//,"Variable"); sub Variable{ return "Variable"; } open Variable,">>c:/temp/variable.txt" or die "Couldnt open! $!"; { no strict 'refs'; *Other_Variable=*Variable; } $\="\n"; $,=","; print $Other_Variable; print keys %Other_Variable; print @Other_Variable; print Other_Variable(); print Other_Variable "Written to Other_Variable at ".localtime();
Now you should see something likesub dump_symbol_table { print "SYMBOL TABLE\n--------------------------------------------- +----------\n"; foreach my $key (sort keys %::) { next unless $key=~/^[\x20-\xff]/; (my $value=$::{$key})=~s/([\x00-\x1f])/sprintf("\\x%02x",ord($ +1))/ge; printf "%20s = %-20s\n",$key,"'$value'"; } print "\n"; } BEGIN { dump_symbol_table } END { dump_symbol_table }
Notice that there is a typeglob '_'? This is the typeglob that holds the dynamic variables $_ @_ %_ and the others. Also notice the aliasing? Other_Variable and Variable both have the same value.Other_Variable = '*main::Variable' ... Variable = '*main::Variable' ... \ = '*main::\' _ = '*main::_'
|
|---|