Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Variables/Perl/variables-1.pl
Normal file
6
Task/Variables/Perl/variables-1.pl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
sub dofruit {
|
||||
$fruit='apple';
|
||||
}
|
||||
|
||||
dofruit;
|
||||
print "The fruit is $fruit";
|
||||
10
Task/Variables/Perl/variables-2.pl
Normal file
10
Task/Variables/Perl/variables-2.pl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
my $x = @a; # Scalar assignment; $x is set to the
|
||||
# number of elements in @a.
|
||||
my ($x) = @a; # List assignment; $x is set to the first
|
||||
# element of @a.
|
||||
my @b = @a; # List assignment; @b becomes the same length
|
||||
# as @a and each element becomes the same.
|
||||
my ($x, $y, @b) = @a; # List assignment; $x and $y get the first
|
||||
# two elements of @a, and @b the rest.
|
||||
my ($x, $y, @b, @c, $z) = @a; # Same thing, and also @c becomes empty
|
||||
# and $z undefined.
|
||||
3
Task/Variables/Perl/variables-3.pl
Normal file
3
Task/Variables/Perl/variables-3.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
use strict;
|
||||
our $fruit; # declare a variable as global
|
||||
our $veg = "carrot"; # declare a global variable and define its value
|
||||
10
Task/Variables/Perl/variables-4.pl
Normal file
10
Task/Variables/Perl/variables-4.pl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
$fruit="apple"; # this will be global by default
|
||||
|
||||
sub dofruit {
|
||||
print "My global fruit was $fruit,"; # use the global variable
|
||||
my $fruit="banana"; # declare a new local variable
|
||||
print "and the local fruit is $fruit.\n";
|
||||
}
|
||||
|
||||
dofruit;
|
||||
print "The global fruit is still $fruit";
|
||||
Loading…
Add table
Add a link
Reference in a new issue