in reply to Event Handling in CGI
Right, now that's said, how's this for fun and giggles:
This is ugly code. It uses symbolic references, it hacks the symbol table, and the sheer amount of curlies and parentheses induces headaches in anybody having to maintain it. But it works.#!/usr/local/bin/perl -w use strict; sub a { print "Hi from a\n"; } sub b { print "Hi from b\n"; } doit('a'); doit('b'); $main::c=1; $main::c++; doit('c'); sub doit { my $func=shift; unless (exists($::{$func}) && defined(&{$::{$func}})) { print "Invalid function called: $func\n"; return 1; }; no strict 'refs'; &{$func}; } __END__ Hi from a Hi from b Invalid function called: c
For educational purposes only. (And I admit, I did it to play around with symbol tables a bit, to get a feel for the things).
Update: Not only is this ugly, if called as a CGI (and the sub to call is provided as a parameter), it is also terribly insecure in this form: it's letting the CGI user call any function that is defined in your script. Bad programmer.
CU
Robartes-
|
|---|