473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to include perl file

I am a new perl programer and I meet a question.
I have a perl file test_1.pl like:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. sub Test;
  3.  
  4. sub Test {
  5.     printf "==========================Hello, perl.\n";
  6.     return 0;
  7. }
  8.  
and In test.pl I want to use the Test function, so I wrote test.pl like:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. #include <test_1.pl>
  4. sub main;
  5. sub main {
  6.     Test;
  7. }
  8.  
  9. main;
  10.  
But this does not work at all.
So can some help me to know how to include a perl file and makes the file mentioned above to work?
Thanks
May 24 '07 #1
4 18240
require '<name of your perl script you want to include>';
May 24 '07 #2
miller
1,089 Expert 1GB
You need to study the following material

perldoc use
perldoc require
cpan Exporter (for the more advanced)

Anyway, here is your code redone. Note that i've renamed the file you were trying to include to Test.pm.

Test.pm
Expand|Select|Wrap|Line Numbers
  1. package Test;
  2.  
  3. sub test {
  4.     printf "==========================Hello, perl.\n";
  5.     return 0;
  6. }
  7.  
  8. 1;
  9.  
  10. __END__
  11.  
test.pl
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Test;
  4.  
  5. sub main {
  6.     Test::test();
  7. }
  8.  
  9. main();
  10.  
- Miller
May 24 '07 #3
Thanks for Miller and other's reply. But after changing the files following Miller's instruction, there still be error :

% perl test.pl
Undefined subroutine &Test::test called at test.pl line 6.

Is there still sth wrong?

Thanks

Files are like below:

test.pl:
#!/usr/bin/perl

use Test;

sub main {
Test::test();
}

main();


test.pm:

package Test;

sub test {
printf "==========================Hello, perl.\n";
return 0;
}

1;

__END__
May 25 '07 #4
miller
1,089 Expert 1GB
test.pm
The test.pm file should be named "Test.pm". Maybe that was just a typo in your post, but that could be a cause of the error.

- Miller
May 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: daniel kaplan | last post by:
i am a newbie PERL programmer, oldtime C guy here....anyway, i am starting some PERL scripts on a shared LINUX server. i cannot store my MySQL login parametrs in the apache config, since it is...
22
by: Weston C | last post by:
I know of course that you can use <script src=""></script> in an HTML document to include javascript code you don't want to spill all over the page. I'm wondering if there's a way to include...
2
by: Amanda aman_DO_da345 | last post by:
Hi! I've done most of my programming in C/C++ and a little in Perl, though until recently I have stayed away from Perl OOP. Now I'm writing my first suite of classes in Perl, and I wonder how...
0
by: Yaseen D M | last post by:
I am want to include a perl (.pl) header file in my asp.net (.aspx) file. Is there a way to include perl file in asp.net. Deost Asp.net support this feature. Regards, Yaseen D M
4
by: Al Franz | last post by:
Editing a script that has a "sub printheader" and "sub printfooter" routine before and after it creates a web page with a message. I would like to customize this script so that I can have my own...
1
by: Bill | last post by:
How can I include a .cgi file in an .ASP file? I've tried #include, Server.Transfer, and Server.Execute (yes, I know the last two are only for ASP, but I tried it anyway). If I have to, I...
4
by: benwylie | last post by:
I am running IIS 6.0 on Windows 2003. I would like to be able to run a perl script from a web page and include the output. I have tried doing it with an ssi: <form action='docsearch.shtml'...
2
by: naveeddil | last post by:
Hello, I use this command for including my ASP files into another it is working perfectly on my XP 2002 SP2, IIS server and also i upload to brinkster.com and working perfectly there but here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.