In print_story I would like to have something simple like, but I doubt it will be that simple.

Sure, it can be that simple, though I might feel safer trying to avoid arbitrary code execution with Safe like

#!/usr/bin/perl -- use strict; use warnings; use Safe; my $str = <<'__STR__'; &print_definitions( file => "some_file_a.txt", headings => ["term","de +finition"],) &print_definitions( file => "some_file_b.txt", headings => ["term","de +finition 1","definition 2"],) &f() &f ( 1 ) &eff( 'a', "A\tB", 3 ) __STR__ my $namespace = __PACKAGE__; my %dispatch = ( eff => \&f, _default => sub {}, ); open my($in), '<', \$str; while( my $line = <$in> ){ if( my( $sub, $args ) = $line =~ /^\&([^\(\s]+)\s*(.*)/) { print "## $sub $args \n"; my $subref = $namespace->can( $sub ); $subref ||= $dispatch{$sub} || $dispatch{_default}; if( $subref ){ $subref->( length $args ? Safe->new->reval( $args ) : () ); } } } close $in; sub print_definitions { print "print_definitions says [ @_ ]\n\n"; } sub f { print "f says [ @_ ]\n\n"; } __END__ ## print_definitions ( file => "some_file_a.txt", headings => ["term" +,"definition"],) print_definitions says [ file some_file_a.txt headings ARRAY(0xb0b93c) + ] ## print_definitions ( file => "some_file_b.txt", headings => ["term" +,"definition 1","definition 2"],) print_definitions says [ file some_file_b.txt headings ARRAY(0xb0b5ec) + ] ## f () f says [ ] ## f ( 1 ) f says [ 1 ] ## eff ( 'a', "A\tB", 3 ) f says [ a A B 3 ]

Does that clear things up for you?


In reply to Re^3: Evaluating subroutines from within data by Anonymous Monk
in thread Evaluating subroutines from within data by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.