# SQL create table _perlsub (name text,code text); insert into _perlsub (name,code) values ('get_time', 'my $x=shift; scalar localtime $x'); # PERL # invoke code for any function, assume strict, $dbh is active, error c +hecking omitted for brevity my $func='get_time'; my $arg=1226940421; my %perlsubs; unless (exists $perlsubs{$func}) { # cache compiled subs my $sth=$dbh->prepare("select code from _perlsub where name='$func' +"); $sth->execute(); my $code=$sth->fetchrow; $sth->finish; eval "$perlsubs{$func}=sub $func { $code }"; } print $perlsubs{$func}->{$arg}; # prints Mon Nov 17 16:47:01 2008
Appreciate all commentary, critical and otherwise!
SSF
In reply to storing perl code in database by sflitman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |