in reply to Re^3: Evaluating subroutines from within data
in thread Evaluating subroutines from within data
Actually, it didn't. I don't see how to incorporate that into the following. print_definitions will not be the only subroutine that I may want to parse from within the __DATA__ of a document which is being parsed by print_story.
The very first line is confusing with the two hyphens you put after the shebang. I looked at Safe, and don't understand what the big deal is, since all blocks to me are separate compartments of code to begin with. I take it that $str is equivalent to __DATA__ in your example. I have no idea what my $namespace = __PACKAGE__; is doing. I see you created a dispatch table, but it appears empty of anything that looks like what I'm trying to do.
print_story is the subroutine I've used the most throughout my site. You've latched onto print_definitions when in the future there could be print_table, print_list, print_monster, print_books, and more. I'd like to put them in __DATA__ when I want to include them within the body of my text.
sub print_story { my ($source,$html) = @_; my $tab = $html ? 3 : 4; start_html() if $html; while (my $line = <$source>) { chomp($line); if ($line =~ m/^&/) { # This is where the code would go to parse the subroutines # within __DATA__. The subroutines to be parsed would be # preceded with an &. } elsif ($line =~ m/^</) { line($tab,$line); } elsif ($line =~ /^[1-6]\s/) { my ($heading,$text) = split(/ /,$line,2); line($tab,qq(<h$heading>$text</h$heading>)); } else { line($tab,qq(<p>$line</p>)); } } line($tab,qq(<p class="author">written by $user</p>)) if $tab == 3; end_html if $html; }
If you could point me to a few perldocs to explain some of what you did and how to incorporate it into print_story I'd be grateful.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Evaluating subroutines from within data
by Anonymous Monk on Jan 09, 2012 at 02:32 UTC |