#!/usr/bin/perl
use Time::Local;
sub subinotherfile
{
# some stuff in here
}
sub getDate
{
# ...
}
sub convertDate
{
# ...
}
Main Topics
Browse All TopicsHow can I call a sub in another file?
I tried:
do 'myotherfile.cgi';
&subinotherfile();
But I get an error:
Undefined subroutine &main::subinotherfile called at /usr/share/parse.cgi line 13.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
could be as simple as adding a require statement in the main script:
require 'myotherfile.cgi'; #assumes it's in the same folder as the main script
subinotherfile();
see "use" and "require" for more details.
http://perldoc.perl.org/fu
http://perldoc.perl.org/fu
Is that the complete contents of myotherfile.cgi? I've tried to recreate this on several platforms and it works in each case. The only time I got the error message you expressed was when I deleted the 'do...' line. I'm wondering if there is anything in that file that is putting the subroutines into a package other than "main".
The error message says that the error is on line 13. What else is in parse.cgi?
I used these files to test:
a.cgi:
#!/usr/bin/perl
do 'b.cgi';
&subinotherfile();
b.cgi:
#!/usr/bin/perl
use Time::Local;
sub subinotherfile {
print "Here\n";
}
Can you please test with these? If they also fail then there is something about your perl environment that is causing the problem. If this test does work then there must be something in your scripts that is causing the problem. Knowing where the problem truly lies will help solve it.
Business Accounts
Answer for Membership
by: ozoPosted on 2006-06-06 at 09:28:30ID: 16844049
What is in myotherfile.cgi?