Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^2: Creating subroutines on the flyby belden (Friar) |
on Feb 16, 2005 at 23:23 UTC ( [id://431786]=note: print w/replies, xml ) | Need Help?? |
If you want to name your subroutines, then just stick in a name at the right spot.
Note that this will throw wierd warnings if you try to create two subs with the same name. You can work around those.... ...but chances are that you don't really need to use eval for whatever you're trying to do. You can probably get away with writing a module which contains all the functions you want to store in your database, and then just store the function names in the database instead. Have your program fetch the right name from the database, then then call it. Here's your stored functions.
And here's your program. Here, rather than fetching function names and function arguments from a database, we'll just get it from the user.
And here's how it might look when you run it
The advantage of storing all your functions in a file and calling them as class methods (i.e. MyFunction->say_hello() rather than MyFunction::say_hello()) is that you have control over what your program does. If your program fetches code from a database, or gets it from the user, then you no longer have control over your program's behavior. Belden
In Section
Seekers of Perl Wisdom
|
|