On Sat, 01 Dec 2001 at 22:36:59 +0000, Jonathan E. Paton wrote:
> Okay, more imagination required. Lets abuse the symbol
> table since I'm bored,
> --- PERL SCRIPT ---
> #!/usr/bin/perl -w
> while (<>) {
> eval qq(\*main\:\:A$.=sub { print \"$_\" });
> }
> if ($. == 0) { exit; }
> my $middle = int ($. / 2) + 1;
> eval qq(main\:\:A$middle\(\));
> --- END PERL SCRIPT
You don't need 'eval' just to munge the symbol table:
perl -ne '${L.$.}=$_;END{print ${L.(1+$.>>1)}}'
or, closer to your idea - this one creates some closures:
perl -e 'while(my$x=<>){*{L.$.}=sub{print$x}};&{L.(1+$.>>1)}'
Ian