2011-01-06 02:48:04 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
sub print_error_message {
|
2011-01-06 02:58:48 +00:00
|
|
|
my ($message) = @_;
|
|
|
|
print STDOUT "ERROR: " . $message . "!!!\n";
|
2011-01-06 02:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
print_error_message("something bad happened");
|
|
|
|
print_error_message("something really horrible happened");
|
|
|
|
print_error_message("something sort of annoying happened");
|
|
|
|
|
|
|
|
|
2011-01-06 02:58:48 +00:00
|
|
|
sub add_two_numbers {
|
|
|
|
my ($x, $y) = @_;
|
|
|
|
my $sum = $x + $y;
|
|
|
|
return $sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
print add_two_numbers(3, 4) . "\n";
|
|
|
|
print add_two_numbers(5, 6) . "\n";
|
|
|
|
print add_two_numbers(7, 8) . "\n";
|
|
|
|
|
|
|
|
|
|
|
|
sub add_two_numbers_and_mult_by_three {
|
|
|
|
my ($x, $y) = @_;
|
|
|
|
my $sum = add_two_numbers($x, $y);
|
|
|
|
my $sum_times_three = $sum * 3;
|
|
|
|
return $sum_times_three;
|
|
|
|
}
|
|
|
|
|
|
|
|
print add_two_numbers_and_mult_by_three(3, 4) . "\n";
|
|
|
|
print add_two_numbers_and_mult_by_three(5, 6) . "\n";
|
|
|
|
print add_two_numbers_and_mult_by_three(7, 8) . "\n";
|
|
|
|
|
|
|
|
|
|
|
|
sub factorial {
|
|
|
|
my ($num) = @_;
|
|
|
|
if ($num == 1) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return $num * factorial($num - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $n (1 .. 10) {
|
|
|
|
print factorial($n) . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-06 02:48:04 +00:00
|
|
|
1;
|
|
|
|
__END__
|