uninitialized variable
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
Re: uninitialized variable
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: uninitialized variable
Chris Devers [EMAIL PROTECTED] m To Adedayo Adeyeye 11/01/2005 10:42 [EMAIL PROTECTED] AM cc beginners-cgi@perl.org Subject Please respond to Re: uninitialized variable [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: uninitialized variable
my $action = param('form_action') || 'any_default_value'; HTH, Sara. - Original Message - From: Chris Devers [EMAIL PROTECTED] To: Adedayo Adeyeye [EMAIL PROTECTED] 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: 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: uninitialized variable
On Tue, 1 Nov 2005 [EMAIL PROTECTED] 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: uninitialized variable
On Tuesday, November 01, 2005 Chris Devers wrote: On Tue, 1 Nov 2005 [EMAIL PROTECTED] 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... 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: uninitialized variable
Chris Devers [EMAIL PROTECTED] m To [EMAIL PROTECTED] 11/01/2005 11:10 cc AMbeginners-cgi@perl.org Subject Re: uninitialized variable Please respond to [EMAIL PROTECTED] l.org On Tue, 1 Nov 2005 [EMAIL PROTECTED] 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 dudegood catch as well . aka || and {} Its a lotus notes thing... : ( Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: uninitialized variable
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.0002 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_ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: uninitialized variable
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:[EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
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: 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 ... 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. Can you use the same login credentials to connect to the database via some other means than the CGI script you're writing? If you can't, then there's the problem; if you can, then something about using that user / 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. -- Chris Devers by¯LcìØL è 8 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: uninitialized variable
Thanks once again. I'm running this script on two different machines, both separate from the machine the Database is running on. 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:[EMAIL PROTECTED] 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: 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 ... 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. Can you use the same login credentials to connect to the database via some other means than the CGI script you're writing? If you can't, then there's the problem; if you can, then something about using that user / 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. -- Chris Devers by¯LcìØL è 8 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: question about uninitialized variable
On Friday, Mar 7, 2003, at 10:42 US/Pacific, Tony Bandy wrote: [..] Just a beginning test page where the end-user submits a name and gets a page back with that name in it. The page works,however, the warning I keep getting is: Use of uninitialized value in concatenation (.) or string... that error message should also have a line number. that would help point to which specific line is causing the problem. [..] Here is a snippet of code that will generate the error messsage above: #!c:\Perl\Perl5.00402\bin\perl.exe -w #Set Perl Parameters #use strict; #The CGI.pm module will take input from the form and process it for you. use CGI qw(:standard); my $name=param(name); print h2You entered: $name p\n; [..] assuming that the 'uninitialized value' error occurred in the print statement, then clearly what got to you did NOT have a 'name' parameter in the query. One strategy would be: my $name = param(name); $name ||= ''; so that if there was no name parameter then it will 'initialize' $name to an empty string. Note from the perldoc CGI as of 2.63 it should have returned an 'empty string' if the query had been of the form name1=name2= or name1name2 so you can check for the version with say [jeeves: 90:] perl -MCGI -e 'print $CGI::VERSION' 2.56[jeeves: 91:] ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
question about uninitialized variable
Hello everyone, Fairly new to the list here (and perl), so if this is an inappropriate post, please forgive me. I've got the Learning Perl book plus a few others...but I'm still scratching my head over this one. Just a beginning test page where the end-user submits a name and gets a page back with that name in it. The page works,however, the warning I keep getting is: Use of uninitialized value in concatenation (.) or string... I also noticed this same type of warning when I attempt to take the same thing (user input) and try to compare it to another variable, using this example-- $my other variable=~/$name/ operator. I can't get anything to match. Here is a snippet of code that will generate the error messsage above: #!c:\Perl\Perl5.00402\bin\perl.exe -w #Set Perl Parameters #use strict; #The CGI.pm module will take input from the form and process it for you. use CGI qw(:standard); my $name=param(name); print h2You entered: $name p\n; Thanks in advance for any help you might be able to provide a newbie. -- Tony Bandy [EMAIL PROTECTED] OHIONET -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question about uninitialized variable
As a relative newbie myself, it appears that you have in essence applied a variable to a variable. I typically use the format my $name=param(name); when I have a form that has a field called name. This form field value (andrew for example) would be stored in param(name) which is then stored in the variable $name. Based on your code snippet, you do not appear to have a value in either holder $name or param(name). As I said earlier, I am pretty new at this too. Others please jump in. Andrew -Original Message- From: Tony Bandy [mailto:[EMAIL PROTECTED] Sent: Friday, March 07, 2003 1:43 PM To: [EMAIL PROTECTED] Subject: question about uninitialized variable Hello everyone, Fairly new to the list here (and perl), so if this is an inappropriate post, please forgive me. I've got the Learning Perl book plus a few others...but I'm still scratching my head over this one. Just a beginning test page where the end-user submits a name and gets a page back with that name in it. The page works,however, the warning I keep getting is: Use of uninitialized value in concatenation (.) or string... I also noticed this same type of warning when I attempt to take the same thing (user input) and try to compare it to another variable, using this example-- $my other variable=~/$name/ operator. I can't get anything to match. Here is a snippet of code that will generate the error messsage above: #!c:\Perl\Perl5.00402\bin\perl.exe -w #Set Perl Parameters #use strict; #The CGI.pm module will take input from the form and process it for you. use CGI qw(:standard); my $name=param(name); print h2You entered: $name p\n; Thanks in advance for any help you might be able to provide a newbie. -- Tony Bandy [EMAIL PROTECTED] OHIONET -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: question about uninitialized variable
Hughes, Andrew wrote: As a relative newbie myself, it appears that you have in essence applied a variable to a variable. I typically use the format my $name=param(name); when I have a form that has a field called name. This form field value (andrew for example) would be stored in param(name) which is then stored in the variable $name. This is one way to think of it, though maybe not the best (at first). You are giving the impression that 'param(name)' is a container and that a value is stored in it, which in this case is not strictly correct. 'param' is a function, that takes an argument 'name' (in this case) and performs some action and then returns a value. So in the sense that it is one way to access a particular value when given a particular parameter it appears to store the information. However there is no underlying structure 'param' that is storing anything, the value is being generated on the fly everytime. Of course, advanced techniques using 'tie' blur the line here that I am drawing. That is probably the underlying cause. The OP mentioned that the page worked, is the name displayed correctly? What line number is indicated in the warning, and what line of code is that? This will give you an idea of which value is uninitialized. http://danconia.org -Original Message- From: Tony Bandy [mailto:[EMAIL PROTECTED] Sent: Friday, March 07, 2003 1:43 PM To: [EMAIL PROTECTED] Subject: question about uninitialized variable Hello everyone, Fairly new to the list here (and perl), so if this is an inappropriate post, please forgive me. I've got the Learning Perl book plus a few others...but I'm still scratching my head over this one. Just a beginning test page where the end-user submits a name and gets a page back with that name in it. The page works,however, the warning I keep getting is: Use of uninitialized value in concatenation (.) or string... I also noticed this same type of warning when I attempt to take the same thing (user input) and try to compare it to another variable, using this example-- $my other variable=~/$name/ operator. I can't get anything to match. Here is a snippet of code that will generate the error messsage above: #!c:\Perl\Perl5.00402\bin\perl.exe -w #Set Perl Parameters #use strict; #The CGI.pm module will take input from the form and process it for you. use CGI qw(:standard); my $name=param(name); print h2You entered: $name p\n; Thanks in advance for any help you might be able to provide a newbie. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]