runtime load of code

A

Alythh

<this could be one of the most basic questions you've heard, but don't
kick me on the teeth please, I've RTFM>

I'm fairly new to Perl, and was trying to develop a program that
1) reads an input file and:
2) uses, to perform some tasks, some subroutines available in external
files, those to be loaded defined by the input file e.g.:

input file:
....
aux_sub1.pl
....

and in the code I call the functions defined in aux_sub1.pl

What I don't understand if this is <exactly> the module mechanism, or
if I have to use something new - I mean, those subs should be loaded
in someway at runtime, while which modules I load is defined once and
for all from the start, isntit?

.... waiting for enlightenment, thanks!

Alessandro Magni
 
A

Anno Siegel

Alythh said:
<this could be one of the most basic questions you've heard, but don't
kick me on the teeth please, I've RTFM>

I'm fairly new to Perl, and was trying to develop a program that
1) reads an input file and:
2) uses, to perform some tasks, some subroutines available in external
files, those to be loaded defined by the input file e.g.:

input file:
...
aux_sub1.pl
...

and in the code I call the functions defined in aux_sub1.pl

What I don't understand if this is <exactly> the module mechanism, or
if I have to use something new - I mean, those subs should be loaded
in someway at runtime, while which modules I load is defined once and
for all from the start, isntit?

What makes you think so? Look up "use" and "require" in perldoc
and note the difference.

Anno
 
G

Gregory Toomey

It was a dark and stormy night, and Alythh managed to scribble:
<this could be one of the most basic questions you've heard, but don't
kick me on the teeth please, I've RTFM>

I'm fairly new to Perl, and was trying to develop a program that
1) reads an input file and:
2) uses, to perform some tasks, some subroutines available in external
files, those to be loaded defined by the input file e.g.:

input file:
...
aux_sub1.pl
...

and in the code I call the functions defined in aux_sub1.pl

What I don't understand if this is <exactly> the module mechanism, or
if I have to use something new - I mean, those subs should be loaded
in someway at runtime, while which modules I load is defined once and
for all from the start, isntit?

... waiting for enlightenment, thanks!

Alessandro Magni

For a start read http://perl.plover.com/FAQs/Namespaces.html

Make sure you know the difference between packages & modules.

gtoomy
 
A

Alythh

OK, it works

foreach $address (@addresses)
{
$mod = $modules{$address};

require $mod;
....
}

.... it just complains about:
Subroutine process_page redefined at ... line 20.
Subroutine action_on_page redefined at ... line 48.

but it's OK enough for me.

thanks

Alessandro Magni
 
D

DOV LEVENGLICK

you are probably getting that because require will only retrieve the
first copy of a subroutine and disregard the other subroutines with the
same name
 
A

Anno Siegel

[another of DOV's top-postings re-arranged]

DOV LEVENGLICK said:
you are probably getting that because require will only retrieve the
first copy of a subroutine and disregard the other subroutines with the
same name

That is mere speculation, and it's wrong. In fact, the messages appear
because require does *not* ignore later re-definitions of the same
subroutine.

Please don't post stuff you just made up of thin air.

Anno
 
B

Brian McCauley

you are probably getting that because require will only retrieve the
first copy of a subroutine and disregard the other subroutines with
the same name

Nonsense.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top