[Mastering-perl] Perl Contexts & Symbol Tables and Typeglobs
brian d foy
brian.d.foy at gmail.com
Tue Jan 2 23:46:32 EST 2007
On 1/2/07, Florian Merges <fmerges at cpan.org> wrote:
> Ch. Symbol Tables and Typeglobs
> =========================
>
> Section: Package and lexical variables
> --------------------------------------------------------
>
> $n and $global should be declared with 'our'
I've never really been fond of our as a way to declare variables. It's
useful to bring a package variable into play when a lexical of the
same name is in scope, but otherwise is just a trick to get around use
strict. If I really want to make something global, I prefer to list
them all in 'use vars' :)
However, for those examples I'm specifically avoiding our() until
later so I don't hit the reader with everything at once.
> The first code example, instead of using the 'foreach' idiom, I would suggest:
> print join "\n", keys %main::;
I could do that, I guess, but it really doesn't add anything to the
discussion. In the later example where I check the definedness on the
var types for each identifier I would have to go back to foreach(), so
I might as use it in the same way in the preceding examples.
>
>
> Section: Package and lexical variables -> Full package specification
> --------------------------------------------------------------------------------------------------
>
> Last example output should be:
>
> In the naked block, our $global is --> I'm the global version
> In lexical, my $global is --> I'm in the lexical version
> The package version is still --> I'm the global version
> In lexical(): I'm the global version
>
> Section: The symbol table
> --------------------------------------
>
> The first code example, instead of using the 'foreach' idiom, I would
> suggest:
>
> print join "\n", keys %main::;
>
> Section: The symbol table -> Naming anonymous subroutines
> -----------------------------------------------------------------------------------------
>
> ..., and then using that function to created two anonymous subroutines.
>
> ==> what?
>
>
> Kind regards,
>
> Florian
>
>
>
>
>
> _______________________________________________
> Mastering-perl mailing list
> Mastering-perl at theperlreview.com
> http://five.pairlist.net/mailman/listinfo/mastering-perl
>
>
>
--
brian d foy <brian.d.foy at gmail.com>
http://www.pair.com/~comdog/
More information about the Mastering-perl
mailing list