guthrie has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: call perl subs in another directory?
by Fletch (Bishop) on Oct 16, 2007 at 20:48 UTC | |
|
Re: call perl subs in another directory?
by gamache (Friar) on Oct 16, 2007 at 20:36 UTC | |
by guthrie (Novice) on Oct 17, 2007 at 02:06 UTC | |
by gamache (Friar) on Oct 17, 2007 at 13:58 UTC | |
by guthrie (Novice) on Oct 17, 2007 at 18:54 UTC | |
by gamache (Friar) on Oct 17, 2007 at 20:13 UTC |