For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > January 2005 > Use Strict









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Use Strict
Graeme St. Clair

2005-01-14, 3:55 am

In accordance with The Rules, I added use strict & use warnings to a script
invoked from a browser page on the same machine. Last time I did this, as
soon as I used the browser page, apache 'error.log' promptly showed scads of
msgs along the lines of '[Wed Dec 08 11:03:52 2004] [error] [client
###.###.###.###] Global symbol "$dbh" requires explicit package name at
c:\PROGRA~1\...\###.pl line 358.' This time, all that happened was that the
browser (IE, alas) walloped off into a loop (maybe) and nothing new ever
came up in the new frame, although there did seem to be disk activity.

I eventually elicited a list of error msgs by just flat out compiling the
thing from the Windows cmd line, but is there something more intelligent I
could have done to force out some diagnostics on the apache log?

Rgds, GStC.


Randy W. Sims

2005-01-14, 3:55 am

Graeme St. Clair wrote:
> In accordance with The Rules, I added use strict & use warnings to a script
> invoked from a browser page on the same machine. Last time I did this, as
> soon as I used the browser page, apache 'error.log' promptly showed scads of
> msgs along the lines of '[Wed Dec 08 11:03:52 2004] [error] [client
> ###.###.###.###] Global symbol "$dbh" requires explicit package name at
> c:\PROGRA~1\...\###.pl line 358.' This time, all that happened was that the
> browser (IE, alas) walloped off into a loop (maybe) and nothing new ever
> came up in the new frame, although there did seem to be disk activity.
>
> I eventually elicited a list of error msgs by just flat out compiling the
> thing from the Windows cmd line, but is there something more intelligent I
> could have done to force out some diagnostics on the apache log?


use CGI::Carp qw( fatalsToBrowser );

See `perldoc CGI::Carp`

Graeme St. Clair

2005-01-14, 3:55 am

Hmm. By the time I'd knocked most of the errors down (and before I read
your reply), the browser started giving 500 after all, and the errors were
being duly logged.

So just for kicks, I commented out all the my()'s that I'd added, then added
your line, and it didn't seem to make any difference to the original hang.
Ah well. Thanks anyway!

Now I have another Q arising out of this. I have an irreducible pair of
'requires explicit package name' msgs that I can't see how to fix. One
example is:-

....perl perl perl
require 'bunch_of_constants.pl';
....perl perl perl
$html .= <<EOF;
....html html html
<form action="$one_constant" target="_blank" method="POST" name="Data
Request" onSubmit="...">
....html html html
EOF

$one_constant is defined in bunch_of_constants.pl, which is in the path all
right, and which is not a package. I've tried
bunch_of_constants::$one_constant and main::$one_constant, but neither
achieved anything.

What do I now need to change?

Rgds, GStC.


-----Original Message-----
From: Randy W. Sims [mailto:ml-perl@ThePierianSpring.org]
Sent: Thursday, January 13, 2005 6:59 PM
To: Graeme St. Clair
Cc: beginners-cgi@perl.org
Subject: Re: Use Strict

Graeme St. Clair wrote:
> In accordance with The Rules, I added use strict & use warnings to a
> script invoked from a browser page on the same machine. Last time I
> did this, as soon as I used the browser page, apache 'error.log'
> promptly showed scads of msgs along the lines of '[Wed Dec 08 11:03:52
> 2004] [error] [client ###.###.###.###] Global symbol "$dbh" requires
> explicit package name at c:\PROGRA~1\...\###.pl line 358.' This time,
> all that happened was that the browser (IE, alas) walloped off into a
> loop (maybe) and nothing new ever came up in the new frame, although there

did seem to be disk activity.
>
> I eventually elicited a list of error msgs by just flat out compiling
> the thing from the Windows cmd line, but is there something more
> intelligent I could have done to force out some diagnostics on the Apache

log?

use CGI::Carp qw( fatalsToBrowser );

See `perldoc CGI::Carp`
Ovid

2005-01-14, 3:55 am

--- "Graeme St. Clair" <Graeme.St.Clair@hds.com> wrote:
> Now I have another Q arising out of this. I have an irreducible pair
> of
> 'requires explicit package name' msgs that I can't see how to fix.
> One
> example is:-
>
> ...perl perl perl
> require 'bunch_of_constants.pl';
> ...perl perl perl
> $html .= <<EOF;
> ...html html html
> <form action="$one_constant" target="_blank" method="POST" name="Data
> Request" onSubmit="...">
> ...html html html
> EOF
>
> $one_constant is defined in bunch_of_constants.pl, which is in the
> path all
> right, and which is not a package. I've tried
> bunch_of_constants::$one_constant and main::$one_constant, but
> neither
> achieved anything.


What needs to change can depend upon what is in
"bunch_of_constants.pl". If, in that script, you've declared your
variables with "my", then you will not be able to easily get at them.
You can create a wrapper subroutine that returns them, however.

If they are truly package variables, though, then you determine the
package that they're in and you put the dollar sign at the front of the
variable name (assuming, in this case, that they're in the "main"
package):

$main::one_constant

However, I would urge you to turn "bunch_of_constants.pl" into a proper
module and using Exporter.

References:

perldoc -f my
perldoc -f package
perldoc perlmod
perldoc Exporter

Cheers,
Ovid

=====
Silence is Evil http://users.easystreet.com/ovid/ph...hy/decency.html
Ovid http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl http://users.easystreet.com/ovid/cgi_course/
Graeme St. Clair

2005-01-14, 3:55 pm

Thanks for the hint - mainly, I'd misplaced the $ sign (story of my
life...).

The problem is by no means fixed yet, as there are several other components
which have been kind of bashed to fit and need to be straightened out, but I
think I now know what to do.

Rgds, GStC.

-----Original Message-----
From: Ovid [mailto:publiustemp-beginnerscgi@yahoo.com]
Sent: Thursday, January 13, 2005 8:09 PM
To: Graeme St. Clair; beginners-cgi@perl.org
Subject: RE: Use Strict

--- "Graeme St. Clair" <Graeme.St.Clair@hds.com> wrote:
> Now I have another Q arising out of this. I have an irreducible pair
> of 'requires explicit package name' msgs that I can't see how to fix.
> One
> example is:-
>
> ...perl perl perl
> require 'bunch_of_constants.pl';
> ...perl perl perl
> $html .= <<EOF;
> ...html html html
> <form action="$one_constant" target="_blank" method="POST" name="Data
> Request" onSubmit="..."> ...html html html EOF
>
> $one_constant is defined in bunch_of_constants.pl, which is in the
> path all right, and which is not a package. I've tried
> bunch_of_constants::$one_constant and main::$one_constant, but neither
> achieved anything.


What needs to change can depend upon what is in "bunch_of_constants.pl".
If, in that script, you've declared your variables with "my", then you will
not be able to easily get at them.
You can create a wrapper subroutine that returns them, however.

If they are truly package variables, though, then you determine the package
that they're in and you put the dollar sign at the front of the variable
name (assuming, in this case, that they're in the "main"
package):

$main::one_constant

However, I would urge you to turn "bunch_of_constants.pl" into a proper
module and using Exporter.

References:

perldoc -f my
perldoc -f package
perldoc perlmod
perldoc Exporter

Cheers,
Ovid

=====
Silence is Evil
http://users.easystreet.com/ovid/ph...hy/decency.html
Ovid http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl http://users.easystreet.com/ovid/cgi_course/
Shaun Fryer

2005-01-14, 3:55 pm

> perldoc -f my
> perldoc -f package
> perldoc perlmod
> perldoc Exporter


Also along the same lines, you can get rid of alot of the grunt work
by using the following on the unix command line (not sure about win32,
sorry ... but try anyway).

h2xs -AXn ModuleName

The result will be a fully setup package template including a basic
unit test (via Test::More), suitable for installation with `make`.

--
=====================
Shaun Fryer
=====================
http://sourcery.ca/
ph: 416-544-9461
=====================

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com