[Chicago-talk] Script comments

brian d foy brian.d.foy at gmail.com
Tue Jan 17 16:20:22 PST 2006


On 1/17/06, Steven Lembark <lembark at wrkhors.com> wrote:

> Lexicals aren't "global", the farthest out they can go
> is the package they live in (vs. global variables that
> can be accessed from everywhere).

Lexicals exist in their scope, not packages (because they aren't
package variables). The package builtin doesn't define a scope. If the
lexical isn't in a block, it's defined in the scope of the file.
Anything else in the file can see it, but things in other files can't.

	#!/usr/bin/perl
	
	my $foo = "Chicago";
	print "In main, foo is $foo\n";
	
	package bar;
	my $quux = "New York";	
	print "In bar, foo is $foo\n";
	print "In bar, quux is $quux\n";
	
	package baz;
	print "In baz, foo is $foo\n";
	print "In baz, quux is $quux\n";

--
brian d foy <brian.d.foy at gmail.com>
http://www.pair.com/~comdog/


More information about the Chicago-talk mailing list