Perl-Sensitive Sunglasses | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
++spartan. Knowing when to do homework is a *good* thing. Wish I had when I was in highschool. :-)
Ok maybe this will help: (Gurus, details are fudged for understanding here) Perl has two flavours of variables, lexical variables and dynamic variables. These are declared in a module in the following way (this is perl 5.6): 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 here 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. Now lets have a quick look at the symbol table for the package the above code ran in. Add this code Now you should see something like 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. So now on to lexical variables. again these have symbol tables, but they are anonymous and bound to each level of scope in the program. But the typeglob issue is still the same.So on to the point (sorry its taking so long) Perl needs a way to tell each of these names apart. Normally it does this via the type symbol before the name, or its position in a statement (such as a print FH "string"; statement). But when we access an element from on ofthe compound data structures we use something _like_ a scalar context, ie we write $array[1] and not @array[1] The second is a list slice and returns a list, the first is an Array fetch from element 1 and returns a scalar. Since there is a $ in front perl could hypothetically get confused and think that we want $array and not @array, but the presence of the square brackets (or a ->[] for a reference) after the variable name tells perl unequivicably that we are talking about an element of @Array and not the scalar $array. Ok, so maybe this will help you a bit, at least with some terms that you can chase down in the documentation. HTH Yves -- You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM) In reply to Re: Re: Re: Re: Sorting strings
by demerphq
|
|