more fun with variables
This commit is contained in:
parent
66a642a2c4
commit
87ae4602f3
@ -9,3 +9,67 @@ print "Hello, $firstname\n";
|
||||
$firstname = "John";
|
||||
|
||||
print "Goodbye, $firstname\n";
|
||||
|
||||
|
||||
my $variable = "\0";
|
||||
my $another_variable = 2;
|
||||
my @array_variable = qw(one two three);
|
||||
|
||||
$variable = 3;
|
||||
print "$variable\n";
|
||||
$variable = 3.1415926;
|
||||
print "$variable\n";
|
||||
$variable = 3.402823669209384634633e+38;
|
||||
print "$variable\n";
|
||||
$variable = $another_variable + 1;
|
||||
print "$variable\n";
|
||||
$variable = 'Can contain text';
|
||||
print "$variable\n";
|
||||
$variable = \$another_variable;
|
||||
print "$variable\n";
|
||||
$variable = \@array_variable;
|
||||
print "$variable\n";
|
||||
|
||||
|
||||
my @Array1 = (1, 2, 3);
|
||||
my @Array2 = (4, 5, 6);
|
||||
my @Array3 = (7, 8, 9);
|
||||
|
||||
@array_variable = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||
print "@array_variable\n";
|
||||
@array_variable = (1 .. 10);
|
||||
print "@array_variable\n";
|
||||
@array_variable = ('John', 'Paul', 'George', 'Ringo');
|
||||
print "@array_variable\n";
|
||||
@array_variable = qw/John Paul George Ringo/;
|
||||
print "@array_variable\n";
|
||||
@array_variable = qw/red blue 1 green 5/;
|
||||
print "@array_variable\n";
|
||||
@array_variable = (\@Array1, \@Array2, \@Array3);
|
||||
print "@array_variable\n";
|
||||
|
||||
my $idx = 2;
|
||||
|
||||
$array_variable[0] = 1;
|
||||
print "@array_variable\n";
|
||||
$array_variable[$idx] = 1;
|
||||
print "@array_variable\n";
|
||||
|
||||
my %hash = (
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
'key3' => 'value3',
|
||||
);
|
||||
print %hash, "\n";
|
||||
|
||||
$hash{'key1'} = 'newval1';
|
||||
print %hash, "\n";
|
||||
|
||||
|
||||
sub fib {
|
||||
my $n = shift();
|
||||
return $n if $n < 2;
|
||||
return fib($n - 1) + fib($n - 2);
|
||||
}
|
||||
|
||||
print fib(14), "\n";
|
||||
|
@ -1,7 +0,0 @@
|
||||
firstname = "Jonathan"
|
||||
|
||||
print "Hello, " + firstname
|
||||
|
||||
firstname = "John"
|
||||
|
||||
print "Goodbye, " + firstname
|
Loading…
Reference in New Issue
Block a user