Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 71 lines (59 sloc) 0.995 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#!/usr/bin/perl

# Copyright 2004-2012, 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();
Something went wrong with that request. Please try again.