Created
March 25, 2014 09:30
-
-
Save tomas-edwardsson/9758070 to your computer and use it in GitHub Desktop.
Function reference in perl
This file contains 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
#!/usr/bin/perl -w | |
# | |
use strict; | |
sub arg { | |
my @args = @_; | |
print "arg - " . join(' ', @args) . "\n"; | |
} | |
sub farg { | |
my @args = @_; | |
print "farg - " . join(' ', @args) . "\n"; | |
} | |
my $fref; | |
foreach my $i (0..8) { | |
if ($i % 2) { | |
$fref = \&farg; | |
} else { | |
$fref = \&arg; | |
} | |
&$fref("a1", "a2", $i); | |
} |
This file contains 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
[tommi@tandoori tmp]$ perl te.pl | |
arg - a1 a2 0 | |
farg - a1 a2 1 | |
arg - a1 a2 2 | |
farg - a1 a2 3 | |
arg - a1 a2 4 | |
farg - a1 a2 5 | |
arg - a1 a2 6 | |
farg - a1 a2 7 | |
arg - a1 a2 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment