Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Writing automatic code from sql

by Corion (Patriarch)
on Oct 11, 2011 at 10:22 UTC ( [id://930776]=note: print w/replies, xml ) Need Help??


in reply to Writing automatic code from sql

I don't understand what you want, and your code helps little. Maybe seeing the table definition and the table contents would help.

I interpret your task to wanting to run code that is stored as a string in the database. Does DBIx::VersionedSubs sound like a solution to your problem?

Replies are listed 'Best First'.
Re^2: Writing automatic code from sql
by speckled (Novice) on Oct 11, 2011 at 11:55 UTC
    What I want is to create calls to defined packages or subs from strings defined in an sql table.
    Given three varchar columns : PACKAGE, SUB, PARAMS I want to create the following code
    PACKAGE->SUB(PARAMS);

      So just use

      use strict; my ($package,$sub,@params) = ("MyPackage","hello_world",'Hello','World +'); $package->$sub(@params); package MyPackage; use strict; sub hello_world { my ($self,@args)=@_; print "In My Package: $_\n" for @args; };
        Here's the code that works:

        my %h; while(my $r = $st->fetchrow_hashref()) { my $mod = $r->{'Module'}; my $sub = $r->{'Subroutine'}; my $par = $r->{'Params'}; $h{$r->{'VarName'}} = sub { $mod->$sub(eval "$par"); }; }
        You've got my +! Thanks again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://930776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-24 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found