| Author |
Lou's Code - need a little more help on mod questions.
|
|
| Lou Hernsen 2005-11-28, 6:55 pm |
| OK...
I have put the mod in the same dir as the main prog.
chmod 644 on mod
chmod 755 on main
however there is an error.
the mod does nothing more that produce HTML and a few calculations.
the mod works fine with out error in my editor.
however the main program does not like how I call stats.pm
i use the following line.
stats;
and the error
Bareword "stats" not allowed while "strict subs" in use at
C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI line 4359. Execution of
C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI aborted due to compilation errors
and I have , at the top after the shebang
use strict;
use stats;
how do I call a mod and not ask to return any var or value?
I just want the mod to run...
thanks
lou
| |
| Charles K. Clarkson 2005-11-28, 6:55 pm |
| Lou Hernsen <mailto:lhernsen1015@wowway.com> wrote:
: Bareword "stats" not allowed while "strict subs" in use at
: C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI line 4359. Execution of
: C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI aborted due to compilation
: errors
What's on the lines near line 4359?
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
| |
| Lou Hernsen 2005-11-29, 3:55 am |
|
----- Original Message -----
From: "Charles K. Clarkson" <cclarkson@htcomp.net>
To: <beginners-cgi@perl.org>
Sent: Monday, November 28, 2005 3:10 PM
Subject: RE: Lou's Code - need a little more help on mod questions.
> Lou Hernsen <mailto:lhernsen1015@wowway.com> wrote:
>
> : Bareword "stats" not allowed while "strict subs" in use at
> : C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI line 4359. Execution of
> : C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI aborted due to compilation
> : errors
>
> What's on the lines near line 4359?
stats;
the command to call the module.
There is nothing wrong with the other lines of code.
I cut the stats subroutine and pasted it into the mod...
I have removes the "stats;" call and the main program runs fine.
| |
| Lou Hernsen 2005-11-29, 3:55 am |
| I did some testing tonight
when I take out
use stats;
and take out
stats;
the program runs perfect.
and the stats.pm runs just fine in my editor.....
so what the command to run the mod in it entirity?
or does it have to be run as one big subroutine?
I will experient with that tommorrow
Lou
| |
| Charles K. Clarkson 2005-11-29, 7:55 am |
| Lou Hernsen <mailto:lhernsen1015@wowway.com> wrote:
: "Charles K. Clarkson" <cclarkson@htcomp.net>
:
: : Lou Hernsen <mailto:lhernsen1015@wowway.com> wrote:
: :
: : : Bareword "stats" not allowed while "strict subs" in use at
: : : C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI line 4359. Execution
: : : of C:\WWW\MYSTIC~1\CGI-BIN\TEST-N~1\MA.CGI aborted due to
: : : compilation errors
: :
: : What's on the lines near line 4359?
:
: stats;
: the command to call the module.
We don't "call" modules. We load them using "use", then we
use them according to how they were written. In the old thread you
wanted to import a subroutine named Speed(). To use that sub on
line 4359, you would call it like this. The error from perl
indicates that you did not export a sub named stats().
Speed();
The reason for this is because Stats.pm might have a hundreds
of subroutines in it. If we had to call all of them on each use of
any of them, we'd be up that smelly old cr . Remember how CGI.pm
works. We call it at the top of the script and then call its
imported subroutines as if we had written them in the "main" name
space.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
PS
The original name of the package was "Stats", not "stats".
"use" is case sensitive. The module should have a name which
matches the package name.
# In a file named "Stats.pm"
package Stats;
use Exporter 'import';
# Any element of this array will be imported into
# calling package namespace (probably main::).
@EXPORT = qw(Speed);
sub Speed
{
$v0 = 1+$Army+$Hero+$Spy;
$v1 = 1+$Army+$Hero+$Spy+$Wagon;
if ($Wagon < 1 && $Horse >= $v0
&& $Saddle >= $v0 && $Blanket >= $v0
&& $Load <= 100)
{$Speed = "1.5";}
elsif ($Wagon == 0 && $Horse >= $v0 && $Load <= 100)
{$Speed = "2";}
elsif ($Wagon > 0 && $Horse >= $v1 && $Load <= 100)
{$Speed = "2.5";}
elsif ($Wagon == 0 && $Load <= 100)
{$Speed = "3";}
elsif ($Load > 100)
{$Speed = (int(.3 * $Load))/10;}
else {$Speed=3;}
# Do your HTML stuff
}
1;
|
|
|
|