in reply to Building an anonymous subroutine
Sorry this is such a cruddy example!$encode = 'p'; $sub_ref = test($encode); sub test { my $e = shift; my $eval1 = 'print "first bit of reusable code\n";'; my $eval2 = 'print "second bit of reusable code\n";'; $e eq 'p'? return sub { eval $eval1; print "you typed 'p' as your option\n"; eval $eval2; }: $e eq 'b'? return sub { eval $eval1; print "you typed 'b' as your option\n"; eval $eval2; }: return sub { eval $eval1; print "you typed 'u' as your option\n"; eval $eval2; }; } $encoded_output = &$sub_ref;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Building an anonymous subroutine
by mem (Acolyte) on Aug 12, 2002 at 12:29 UTC | |
|
Re: Re: Building an anonymous subroutine
by Anonymous Monk on Aug 13, 2002 at 00:37 UTC |