Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Creating subroutines on the fly

by artist (Parson)
on Feb 16, 2005 at 17:17 UTC ( [id://431647]=note: print w/replies, xml ) Need Help??


in reply to Creating subroutines on the fly

While it is possible as mentioned, I like to prefer a library of sub routines with specific names, that you can just include in your calling program. It may be easier to maintain and can provide less fear of wrong-doing or less debugging.

Replies are listed 'Best First'.
Re^2: Creating subroutines on the fly
by Tanktalus (Canon) on Feb 16, 2005 at 17:45 UTC

    You extend this a bit, and you have what is called an "API". You extend it further, and you get a mini language.

    IMO, the original post isn't quite screaming (maybe loudly speaking) for a mini language, but if robustness is an important issue, a mini language may be in order. Using eval is one thing, and may be great if all interactions to that column in the db is through a perl programmer. Using a mini language allows you to go the extra step and allow anyone to update it, assuming you have enough flexibility in your library of subroutines.

Re^2: Creating subroutines on the fly
by hakkr (Chaplain) on Feb 16, 2005 at 17:38 UTC
    hi you dont need to use eval although it is probably safer,
    my $subref = sub {print "hello"}; &$subref();
Re^2: Creating subroutines on the fly
by monsieur_champs (Curate) on Feb 17, 2005 at 13:35 UTC
    artist wrote:
    While it is possible as mentioned, I like to prefer a library of sub routines with specific names, that you can just include in your calling program. It may be easier to maintain and can provide less fear of wrong-doing or less debugging.

    Fellow artist
    I see this as a distributed library implementation. Would love to know about better ways of implementing this, so I can use this to my own projects.

    Maybe the better approach would be to store and retrieve modules from the database, and overload use or require to correctly load your module from the database.

    Anyway, I would love to read more about this approach, and about distributed shared perl modules.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-24 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found