- or download this
{ # beginning of lexical scope
my $foo;
} # end of lexical scope
- or download this
{ # begin lexical scope
...
$foo is: a string
$foo is: undefined
- or download this
my $ref;
{ # begin lexical scope
...
$ref refers to: something in a lexical scope
$foo is: undefined
- or download this
{
my $foo = "a lexical variable";
...
$bar is: a package variable
$foo is: undefined
$bar is: a package variable
- or download this
use strict;
my $foo = "defined";
...
foo is undef during BEGIN phase
foo is defined at runtime
- or download this
## lextut1.pl
my $foo = "in lextut1.pl's lexical file scope";
print "\$foo is: ", (defined $foo ? $foo : "undefined"), $/;
- or download this
perl -e 'require "lextut1.pl"; \
print "\$foo is: ", (defined $foo ? $foo : "undefined"), $/;'
$foo is: in lextut1.pl's lexical file scope
$foo is: undefined
- or download this
sub foo
{ # begin lexical scope
...
$x in foo() is: a string
$x in bar() is: undefined
- or download this
open(SRC, $0) or die("ack: $!");
my @lines = <SRC>;
...
bareword found: print
$w is: undefined
$line is: undefined
- or download this
## otherwise $r would be auto-vifified as a package global
use strict;
...
Global symbol "$r" requires explicit package name at - line 1.
Execution of - aborted due to compilation errors.
- or download this
my $foo = "file scope";
{
...
$foo is: inner scope
$foo is: outer scope
$foo is: file scope
- or download this
my @list = qw(a list of words);
for my $w (@list) {
...
list: begins with a consonant
of: begins with a vowel
words: begins with a consonant
- or download this
sub foo {
print " \$x is: $x\n";
...
$x is: altered state
$x is: original state
- or download this
{ # begin lexical scope
...
$x is: auto-vivified
$x is: undefined
$main::{x} is: *main::x
- or download this
use IO::File;
...
print "\$foo is: ", (defined $foo ? $foo : "undefined"), $/;
a, comma, separated, list, of, words
- or download this
{
package foo;
...
$x is: in foo
$foo::x is: in foo
- or download this
## set stricture checking for the rest of the file scope
use strict;
...
return $count;
}