How can I call a sub in a dedicated file?

D

Davy

Hi all,

If I want to call a sub function in a dedicated file like "my_sub.pl",
how to do that?

Or if I have a lot of Perl file contain sub function, shall I use
something like package?

Please give me some reference, thanks!

Best regards,
Davy
 
A

anno4000

[newsgroups trimmed]

Davy said:
Hi all,

If I want to call a sub function in a dedicated file like "my_sub.pl",
how to do that?

You load the file, then call the sub. See "perldoc -f use" and
"perldoc -f require".
Or if I have a lot of Perl file contain sub function, shall I use
something like package?

Yes, probably. See "perldoc perlmod" for how to organize your Perl
subs.

Anno
 
P

Paul Lalli

Davy said:
If I want to call a sub function in a dedicated file like "my_sub.pl",
how to do that?

Or if I have a lot of Perl file contain sub function, shall I use
something like package?

No where near enough information given. Please post a
short-but-complete script (or scripts) which demonstrate what you want
to do. If the file contains subroutine definitions, you can simply
require 'my_sub.pl';
and then call the subroutine like you would any other subroutine. If
the code is contained in a package, you either have to export the
subroutine from the package file and import it in the main file, or you
have to fully qualify it (that is, precede the subroutine name with the
name of the package and two colons).
Please give me some reference, thanks!

perldoc -f require
perldoc perlmod
perldoc perlmodlib
perldoc Exporter

Paul Lalli
 
P

Paul Lalli

[newsgroups trimmed]

That was rather obnoxious and pointless, Anno. The OP very correclty
cross-posted instead of multi-posted, and you completely circumvented
the benefits of that decision - I was reading perl.beginners at the
time, and therefore did not see that you had answered the OP's question
in clpm. Had I, I would not have wasted my time by answering an
already answered question....

Paul Lalli
 
A

anno4000

Paul Lalli said:
[newsgroups trimmed]

That was rather obnoxious and pointless, Anno. The OP very correclty

Huh? I trimmed perl.beginners because my news server doesn't carry it
and complained. There was no critique expressed and none implied.

Anno
 
D

Dr.Ruud

Paul Lalli schreef:
anno4000:
[newsgroups trimmed]

That was rather obnoxious and pointless, Anno. The OP very correc[tl]y
cross-posted instead of multi-posted, and you completely circumvented
the benefits of that decision - I was reading perl.beginners at the
time, and therefore did not see that you had answered the OP's
question in clpm. Had I, I would not have wasted my time by
answering an already answered question....

Maybe his newsclient just refused to post to an unknown group. I have
even heard of newsservers that allow themselves to change the Newsgroups
header field.
 
P

Paul Lalli

Paul Lalli said:
[newsgroups trimmed]

That was rather obnoxious and pointless, Anno. The OP very correclty

Huh? I trimmed perl.beginners because my news server doesn't carry it
and complained. There was no critique expressed and none implied.

My apologies. I misunderstood the reasoning. Mis-guessed, to be more
accurate, since there was no indication either way.

Sorry,
Paul Lalli
 

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,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top