#!/usr/bin/perl
# Copyright 2004-2013, Paul Johnson (paul@pjcj.net)
# This software is free. It is licensed under the same terms as Perl itself.
# The latest version of this software should be available from my homepage:
# http://www.pjcj.net
sub unused { 0 }
sub empty { }
sub gen
{
my $x = shift;
sub
{
my $y = shift;
return $x + $y if $y;
}
};
my $o = gen(1);
my $p = $o->(7);
my $q = $o->(8);
my $r = gen(1)->(2);
my $s = gen(3)->(4);
my $t = gen(5)->(6);
print "$p, $q, $r, $s, $t\n";
for my $func (qw(f1 f2 f3))
{
no strict "refs";
*$func = sub
{
print "$func\n";
}
}
f1();
f2();
sub AUTOLOAD
{
my $func = $AUTOLOAD;
$func =~ s/^.*:://;
no strict "refs";
if ($func eq "add")
{
*$func = sub
{
print "Add!\n";
};
}
else
{
*$func = sub
{
print "$func\n";
};
}
goto &$func
}
add();
add();
add();
qaz();
wsx();