2011-01-04 02:54:52 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2011-01-04 02:56:01 +00:00
|
|
|
my $firstname = "Jonathan";
|
2011-01-04 02:54:52 +00:00
|
|
|
|
|
|
|
print "Hello, $firstname\n";
|
2011-01-04 02:56:01 +00:00
|
|
|
|
|
|
|
$firstname = "John";
|
|
|
|
|
|
|
|
print "Goodbye, $firstname\n";
|
2011-01-05 03:27:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
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";
|