Hi Monks,
I'm new to using modules and have a couple of questions regarding the following code. Note that I've included the main script named power.cgi and the module named Test.pm.
#### Begin main script power.cgi
#!/usr/local/bin/perl
use strict;
use CGI qw(:standard);
#use lib '/httpd/cgi-bin/module';
use lib '.';
#use Test;
#use Test qw(&power);
use Test qw($hello_away &power);
my $hello_here = 'hello world from here';
# Call power in Test.pm
my $value = power(4);
print header,
start_html('Using Module'),
"<p>$hello_here</p>",
"<p>$hello_away</p>",
"$value",
end_html,
;
#### End of main script
#### Begin module Test.pm
package Test;
use strict;
use base 'Exporter';
our @EXPORT = qw($hello_away);
our @EXPORT_OK = qw(&power);
our $hello_away = 'hello world from away';
sub power {
my $var = shift;
$var *= $var;
return $var;
}
1;
#### End module
My questions are:
1) What is the difference between specifying
use lib '/httpd/cgi-bin/module'; and
use lib '.';?
2) It seems I have to have either two use statements
use Test; and
use Test qw(&power); or just this one
use Test qw($hello_away &power);. Which is the preferred method?
3) How can the code be improved?
Thanks in anticpation =)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.