Created
July 5, 2015 06:53
-
-
Save ynonp/178f2a9ab1141ae321e2 to your computer and use it in GitHub Desktop.
subroutine demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use v5.08; | |
sub say { | |
print @_, "\n"; | |
} | |
say("Hello"); | |
say("Hello", "World"); | |
say(10, 20, 30, "Bye bye love"); | |
my @a = (2, 3, 5); | |
say @a; | |
sub square_2 { | |
my ($x, $y) = @_; | |
($x ** 2, $y ** 2); | |
} | |
sub square_all { | |
my @result; | |
foreach my $item (@_) { | |
push @result, $item * $item; | |
} | |
return @result; | |
} | |
my @res = square_all(2, 3, 5); | |
my ($a, $b, $c) = square_all(2, 3, 5); | |
sub add_2 { | |
my ($x, $y) = @_; | |
$x + $y; | |
} | |
# $z is 25 | |
my $z = add_2(10, 15); | |
sub hello_world { | |
# Inside function - all arguments @_ | |
my ($text) = @_; | |
print "**************************************************\n"; | |
print "* *\n"; | |
print "* $text *\n"; | |
print "* *\n"; | |
print "**************************************************\n"; | |
} | |
hello_world("All my bags are packed", 10, 20); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment