In a batch-export script at at work, we constantly modify sites to which we need to export data. Each site has different needs, parameters, etc. To solve the problem, we created different .pl files that get 'require()'d, and functions called dynamically in the &$sub_name manner. The problem is if one script (that gets require()d) has a type-o, it will cause the full batch-post script to fail. Here was my solution; hope this is useful to anyone needing to call dynamic functions that are changed in multiple files by multiple people frequently.
my $PREFIX = '/home/xpost-scripts'; my %xscripts = ( site_a => 'a_funct', site_b => 'b_funct' ); foreach (keys(%xscripts)) { if (!system("perl -cw $PREFIX/$_")) { # perl -cw exits with '0' if +no errors. require ("$PREFIX/$_"); } else { print STDERR "Warning: File $_ had errors!\n"; } } # ... Here, we grabbed the Function name from a DB query. It's a hash +for this example. foreach (keys(%xscripts)) { if (defined($xscripts{$_})) { &$xscripts{$_}("A parameter"); } else { print STDERR "Error. Could not call function $xscripts{$_}\n"; } }

In reply to Dynamically loading perl files (and calling dynamic functions) with error checking. by Anonymous Monk

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.