go ahead... be a heretic | |
PerlMonks |
Evaluating subroutines from within databy Lady_Aleena (Priest) |
on Jan 06, 2012 at 23:50 UTC ( [id://946683]=perlquestion: print w/replies, xml ) | Need Help?? |
Lady_Aleena has asked for the wisdom of the Perl Monks concerning the following question: I discussed this a while ago in the chatter box, but I can't remember what was suggested. I have a subroutine called print_story which, by default, wraps the lines of my __DATA__ or a file handle in <p></p> tags if the line doesn't start with a number between 1 and 6 or a < which indicates that the line has an HTML tag already. Normally this is all I need, however I've come upon a situation where I need to insert another subroutine into the data to keep the flow of what I'm printing to the screen and to avoid having to make a lot of little files for single sentences. Here is a sample of use.
Now, if the story has a definition list in it, I would like to use my subroutine print_definitions in my data to keep the flow.
I've tried preceding the line with a & and then using eval. The only way that it would work is if I used the full name of the subroutine, which in this case would be Base::HTML::print_definitions(). In the future I may want to print a list of links or use another subroutine I am writing for printing tables. I really don't want to have to use the full names of each subroutine which is part of the text. The following is the code for both print_story and print_definitions which prints the results I expect by themselves. However, I just haven't figured out the best way of getting them to work together. start_html and end_html are the templates I use on every page of my site. The line subroutine just adds tabs to the beginning of a line and then prints a newline after the line. get_hash does what it says, it gets a hash from a data file.
Have a cookie and a very nice day!
Lady Aleena
Back to
Seekers of Perl Wisdom
|
|