Did you try it out? It just works(tm).
perl -e 'sub one{print "one\n"};sub two{one()};two()'Er... yes. It works exactly how you'd expect it to. Or, at least, how I'd expect it to. What did you try? What happened when you tried it?
sub a_subroutine {
print "this is a subroutine\n";
}
sub another_subroutine {
print "this is another subroutine\n";
a_subroutine();
}
another_subroutine();
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
I think you should spend some time in the first chapters of some Perl books for beginners, like Learning Perl by our own merlyn, or Beginning Perl by Simon Cozens. If you look closely at the latter page, you can find a link to a free online version.
use strict;
use warnings;
bongo(\&bingo);
sub bingo {
print "bingo";
}
sub bongo {
my $p = $_[0];
$p->();
}
sub subroutine_1 {
my $val = subroutine_2();
print "$val this is subroutine_2 output!";
}
sub subroutine_2 {
return "w00t!";
}
sub :: {return lc pop}
sub jonadab {
my $lex = shift;
@ARGV=qw(http://);
return sub{
my ($ical) = @_;
my $closure = :: $lex.".".$ical."/".$/;
}}
my $foo = jonadab("PerlMonks");
$\=$foo->("Org");
print shift;
Note: if you turn in code like that for homework, don't expect a good grade.
perlmonks.org content © perlmonks.org and Anonymous Monk, bart, davorg, jkva, jonadab, tamaguchi, TedPride, tirwhan
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03