I have a main script that posts info to a web page. I want to have a way to add other fields to the display, and make it modular - so I want to have a directory of small scripts, each of which knows how to make it's own flavor of output.

The main script would then get a list of scripts in the directory, and then run a specific method from each. E.g. the directory contains (x.pl. y.pl. z.pl), and I then want to run x::display(), y::display(), ...

I can certainly get the list of file names, but an most sure how to then run methods on them. I do not want to run the entire file (x.pl), as some of it is for data update, which will also do a similar thing but is cron driven, not web driven.

Must be simple, but .. not obvious to me!

Thanks, Gregory

My code looks like this; but the subroutine call won't work. ------------------------------------------ for my $file (glob "$Sources/*.pl") { $file =~ s/(.*).pl/$1/; my $name = $file."::display"; print " Function:: ", $name, "\n"; &${name}(); } ------------------------------------------ and in Sources/data1.pl:: package Data1; my $name = "Data1"; sub update() { print "Update Data.1 source\n"; } sub display() { print "Display Data.1 source\n"; } sub setup() { print "Setup Data.1 source\n"; }

In reply to call perl subs in another directory? by guthrie

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.