Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Scope-modifiers/Perl/scope-modifiers-1.pl
Normal file
9
Task/Scope-modifiers/Perl/scope-modifiers-1.pl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use strict;
|
||||
$x = 1; # Compilation error.
|
||||
our $y = 2;
|
||||
print "$y\n"; # Legal; refers to $main::y.
|
||||
|
||||
package Foo;
|
||||
our $z = 3;
|
||||
package Bar;
|
||||
print "$z\n"; # Refers to $Foo::z.
|
||||
13
Task/Scope-modifiers/Perl/scope-modifiers-2.pl
Normal file
13
Task/Scope-modifiers/Perl/scope-modifiers-2.pl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package Foo;
|
||||
my $fruit = 'apple';
|
||||
package Bar;
|
||||
print "$fruit\n"; # Prints "apple".
|
||||
{
|
||||
my $fruit = 'banana';
|
||||
print "$fruit\n"; # Prints "banana".
|
||||
}
|
||||
print "$fruit\n"; # Prints "apple".
|
||||
# The second $fruit has been destroyed.
|
||||
our $fruit = 'orange';
|
||||
print "$fruit\n"; # Prints "orange"; refers to $Bar::fruit.
|
||||
# The first $fruit is inaccessible.
|
||||
10
Task/Scope-modifiers/Perl/scope-modifiers-3.pl
Normal file
10
Task/Scope-modifiers/Perl/scope-modifiers-3.pl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use 5.10.0;
|
||||
|
||||
sub count_up
|
||||
{
|
||||
state $foo = 13;
|
||||
say $foo++;
|
||||
}
|
||||
|
||||
count_up; # Prints "13".
|
||||
count_up; # Prints "14".
|
||||
17
Task/Scope-modifiers/Perl/scope-modifiers-4.pl
Normal file
17
Task/Scope-modifiers/Perl/scope-modifiers-4.pl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
our $camelid = 'llama';
|
||||
|
||||
sub phooey
|
||||
{
|
||||
print "$camelid\n";
|
||||
}
|
||||
|
||||
phooey; # Prints "llama".
|
||||
|
||||
sub do_phooey
|
||||
{
|
||||
local $camelid = 'alpaca';
|
||||
phooey;
|
||||
}
|
||||
|
||||
do_phooey; # Prints "alpaca".
|
||||
phooey; # Prints "llama".
|
||||
Loading…
Add table
Add a link
Reference in a new issue