
rGeoffrey
User
/ Moderator
Jun 8, 2001, 1:05 PM
Post #3 of 4
(688 views)
|
Re: Calling one script from within another
[In reply to]
|
Can't Post
|
|
This is a good time to make a module to use from each script. As an example consider these two files... testPage.pl
#!/usr/local/bin/perl use strict; use Page; print &Header ('test of Page.pm'), "Some content would be here", &Footer (); Which calls Page.pm
#!/usr/local/bin/perl package Page; use strict; BEGIN{ use Exporter (); use vars qw ($VERSION @ISA @EXPORT); $VERSION = 0.10; @ISA = qw (Exporter); @EXPORT = qw (&Header &Footer); } ################################################ subroutine header begin ## ################################################## subroutine header end ## sub Header { my ($title) = @_; $title = qq(<title>$title</title>) if ($title); #///////////////////////////message my $string = <<EOF; Content-type: text/html <html> <head> $title </head> <body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0"> EOF #///////////////////////////message return ($string); } ################################################ subroutine header begin ## ################################################## subroutine header end ## sub Footer { #///////////////////////////message my $string = <<EOF; <hr> <center>Copyright © 2001 by me</center> </body></html> EOF #///////////////////////////message return ($string); } ########################################################################### ########################################################################### 1; #this line is important, without it your module may not work correctly You can modify Header () and Footer () to return any text you want, but this should get you moving in the right direction. Page.pm should exist in the same directory as all the scripts that use it or in one of the directories in your @INC. If you are not sure which directories they are type... on the command line or at a DOS prompt. The last section of stuff you get will be the contents of the @INC. And now for a bit of shameless advertising. I will be presenting a talk on "Making a Module" at YAPC::America::North in Montreal next week. After the talk I will return to this thread and include a link to the slides, but I don't want to spoil the surprise by making them public yet. The original title was "Making a Module: And All the Crap that CPAN Wants Too", but I have to send my slides through the lawyers at work so I have simplified the title. -- Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?
|