For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > November 2005 > uninitialized variable









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 uninitialized variable
Adedayo Adeyeye

2005-11-01, 6:55 pm

Chris Devers

2005-11-01, 9:55 pm

On Tue, 1 Nov 2005, Adedayo Adeyeye wrote:

> my $action = param('form_action');


Try setting a default value when 'form_action' isn't specified:

my $action = param('form_action') or '';

Or set it to 0, or 'do nothing' or undef, or whatever is appropriate.


--
Chris Devers
DBSMITH@OhioHealth.com

2005-11-01, 9:55 pm


Chris Devers
<cdevers@pobox.co
m> To
Adedayo Adeyeye
11/01/2005 10:42 <a.adeyeye@netcomng.com>
AM cc
beginners-cgi@perl.org
Subject
Please respond to Re: uninitialized variable
beginners-cgi@per
l.org











On Tue, 1 Nov 2005, Adedayo Adeyeye wrote:

> my $action = param('form_action');


Try setting a default value when 'form_action' isn't specified:

my $action = param('form_action') or '';

Or set it to 0, or 'do nothing' or undef, or whatever is appropriate.


--
Chris Devers

--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>


****************************************
****************************************
****
****************************************
****************************************
****

from Perl Best Practices


use

my $action = param('form_action') | | q{ }


instead of

or ' '

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams


Sara

2005-11-01, 9:55 pm

my $action = param('form_action') || 'any_default_value';

HTH,
Sara.


----- Original Message -----
From: "Chris Devers" <cdevers@pobox.com>
To: "Adedayo Adeyeye" <a.adeyeye@netcomng.com>
Cc: <beginners-cgi@perl.org>
Sent: Tuesday, November 01, 2005 8:42 PM
Subject: Re: uninitialized variable


> On Tue, 1 Nov 2005, Adedayo Adeyeye wrote:
>
>
> Try setting a default value when 'form_action' isn't specified:
>
> my $action = param('form_action') or '';
>
> Or set it to 0, or 'do nothing' or undef, or whatever is appropriate.
>
>
> --
> Chris Devers
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>

Chris Devers

2005-11-01, 9:55 pm

On Tue, 1 Nov 2005 DBSMITH@OhioHealth.com wrote:

> from Perl Best Practices
>
> use
>
> my $action = param('form_action') | | q{ }
>
> instead of
>
> or ' '



Good catch. Yes, that's clearer than simple apostrophes.

However, you probably didn't really mean | | over ||, right ? :-)

I still think 'or' is clearer than '||' for this kind of thing, but if
PBP had a different rationale I can't remember what it was...


--
Chris Devers
Dave Doyle

2005-11-01, 9:55 pm

>On Tuesday, November 01, 2005 Chris Devers wrote:
>
>Good catch. Yes, that's clearer than simple apostrophes.
>
>However, you probably didn't really mean | | over ||, right ? :-)
>
>I still think 'or' is clearer than '||' for this kind of thing, but if
>PBP had a different rationale I can't remember what it was...


My understanding is that you use || because it's more tightly bound than
'or'. Although I would suggest something further for this:

my $action
= defined( param('form_action') )
? param('form_action')
: 'default_value'
;

This way if zero is a valid value for the form_action parameter it will
still pass through. Depends how you're doing things really.

Further, Data::FormValidator might be of interest in the future.

--
Dave Doyle
DBSMITH@OhioHealth.com

2005-11-01, 9:55 pm


Chris Devers
<cdevers@pobox.co
m> To
DBSMITH@OhioHealth.com
11/01/2005 11:10 cc
AM beginners-cgi@perl.org
Subject
Re: uninitialized variable
Please respond to
beginners-cgi@per
l.org










On Tue, 1 Nov 2005 DBSMITH@OhioHealth.com wrote:

> from Perl Best Practices
>
> use
>
> my $action = param('form_action') | | q{ }
>
> instead of
>
> or ' '



Good catch. Yes, that's clearer than simple apostrophes.

However, you probably didn't really mean | | over ||, right ? :-)

I still think 'or' is clearer than '||' for this kind of thing, but if
PBP had a different rationale I can't remember what it was...


--
Chris Devers
****************************************
*************************************


yes dude....good catch as well ..... aka || and {}
Its a lotus notes thing... : (


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145

Shawn Corey

2005-11-01, 9:55 pm

Adedayo Adeyeye wrote:
> Hello,
>
> I'm getting an error when trying to run a script. Part of the scripts is
>
> Line 10 my $action = param('form_action');
>
> .
>
> Line 14 Search_DB() if($action eq 'search');
>
> The error I get is:
>
>
>
> [Tue Nov 1 16:28:41 2005] connect_script.cgi: Use of uninitialized value in
> string eq at connect_rodopi.cgi line 14.
>
>
>
> How am I supposed to initialize this value?
>
>
>
> Kind regards
>
>
>
> Dayo
>
>
>
>
>
>



Two things you can do:

line 10: my $action = param('form_action') || '';

or

line 14: Search_DB() if( defined( $action ) && $action eq 'search' );

The first solution implies that the value '' for $action will never be
tested for. I prefer the second one. You can always put it in its own if
statement:

if( defined( $action )){
# list of actions
...
Search_DB() if $action eq 'search';
...
}else{
# page for no action
...
}


--

Just my 0.00000002 million dollars worth,
--- Shawn

"Probability is now one. Any problems that are left are your own."
SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_
David Dorward

2005-11-01, 9:55 pm

On Tue, Nov 01, 2005 at 04:34:45PM +0100, Adedayo Adeyeye wrote:

> I'm getting an error when trying to run a script. Part of the scripts is


> my $action = param('form_action');
> if($action eq 'search');


> The error I get is:
> Use of uninitialized value in string eq at connect_rodopi.cgi line 14.


Looks more like a warning then an error to me.

> How am I supposed to initialize this value?


By assigning something to it, but in this case its possibly better to
test if something was assigned to it.

if (defined $action && $action eq 'search') ...

or

if (!defined $action) {
...
} elsif ($action eq 'search') {
...
}

--
David Dorward http://dorward.me.uk

Paul Lalli

2005-11-01, 9:55 pm

Chris Devers wrote:
> On Tue, 1 Nov 2005 DBSMITH@OhioHealth.com wrote:
>
>
>
> Good catch. Yes, that's clearer than simple apostrophes.
>
> However, you probably didn't really mean | | over ||, right ? :-)
>
> I still think 'or' is clearer than '||' for this kind of thing, but if
> PBP had a different rationale I can't remember what it was...


Uhm, possibly that one works while the other does not?

$ perl -MO=Deparse,-p -e'my $val = func('foo') or $default'
((my $val = func('foo')) or $default);
-e syntax OK
$ perl -MO=Deparse,-p -e'my $val = func('foo') || $default'
(my $val = (func('foo') || $default));
-e syntax OK

= has a higher precedence than or, but a lower precedence than ||.
Your original solution will not assign a default value at all.

Paul Lalli

Adedayo Adeyeye

2005-11-01, 9:55 pm

Thanks. That's cleared now.

I'm also trying to connect to an mssql db from a cgi, and I'm getting the
following error:

Cannot connect: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does
not exist or access denied. (SQL-08001)[Microsoft][ODBC SQL Server
Driver][DBNETLIB]ConnectionOpen (Connect()). (SQL-01000)(DBD:
db_login/SQLConnect err=-1)Aborting at C:\Savant\cgi-bin\connect_rodopi.cgi
line ...

Help appreciated.

Kind regards

Dayo



-----Original Message-----
From: David Dorward,,, [mailto:david@us-lot.org] On Behalf Of David Dorward
Sent: Tuesday, November 01, 2005 4:40 PM
To: beginners-cgi@perl.org
Subject: Re: uninitialized variable

On Tue, Nov 01, 2005 at 04:34:45PM +0100, Adedayo Adeyeye wrote:

> I'm getting an error when trying to run a script. Part of the scripts is


> my $action = param('form_action');
> if($action eq 'search');


> The error I get is:
> Use of uninitialized value in string eq at connect_rodopi.cgi line 14.


Looks more like a warning then an error to me.

> How am I supposed to initialize this value?


By assigning something to it, but in this case its possibly better to
test if something was assigned to it.

if (defined $action && $action eq 'search') ...

or

if (!defined $action) {
...
} elsif ($action eq 'search') {
...
}

--
David Dorward http://dorward.me.uk


--
To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
For additional commands, e-mail: beginners-cgi-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Chris Devers

2005-11-01, 9:55 pm

Adedayo Adeyeye

2005-11-01, 9:55 pm

Thanks once again.

I'm running this script on two different machines, both separate from =
the
machine the Database is running on.=20

It works on one Server and it fails on the other. I believe that, it's
trying to connect to a local database on the system it fails rather than
connecting to an external database on another system.

What's the syntax to specify a DSN that includes the IP of Remote MSSql
Server when using dbi-odbc?

Kind regards

Dayo



-----Original Message-----
From: Chris Devers [mailto:cdevers@pobox.com]=20
Sent: Tuesday, November 01, 2005 10:23 PM
To: Adedayo Adeyeye
Cc: Perl Beginners - CGI List
Subject: RE: uninitialized variable

On Tue, 1 Nov 2005, Adedayo Adeyeye wrote:

> I'm also trying to connect to an mssql db from a cgi, and I'm getting =

the
> following error:
>=20
> Cannot connect: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL=20
> Server does not exist or access denied. (SQL-08001)[Microsoft][ODBC=20
> SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).=20
> (SQL-01000)(DBD: db_login/SQLConnect err=3D-1)Aborting at=20
> C:\Savant\cgi-bin\connect_rodopi.cgi line ...


This seems to be the meat of the problem:

SQL Server does not exist or access denied

Sounds like a DB admin issue to me.=20

Can you use the same login credentials to connect to the database via=20
some other means than the CGI script you're writing? If you can't, then=20
there's the problem; if you can, then something about using that user /=20
password pair from the host where your CGI script is running is broken.

Either way, it sounds like a SQL Server admin config issue, not CGI.



--=20
Chris Devers

by=AFLc=EC=D8L =E8=858


Sponsored Links







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

Copyright 2008 codecomments.com