Gossamer Forum
Home : General : Perl Programming :

Use of uninitialized value in concatenation (.) or string

Quote Reply
Use of uninitialized value in concatenation (.) or string
Can any one point me in the right direction with this script I dont understand the message I am getting I must have dons something realy wrong but dont have a clue what it is. I have slightly edited the error message as it repeated for about 9 inches at least! Line 12 is SELECT * FROM Area and that is correct and gives me the table and info I need when run in SQL prompt.

Code:
#!c:\perl\bin\perl.exe -w
print "Content-Type: text/html\n\n";
use CGI ":standard";
use CGI::Carp qw(fatalsToBrowser);
my $Code=param("Code");
my $Name=param("Name");
my $Hight=param("Hight");
use DBI;
my $DBH = DBI->connect("DBI:mysql:Guide")or die "\n ($DBI::err): $DBI::errstr\n";
my $query = $DBH->prepare(qq{SELECT * FROM Area});
$query->execute()or die "\n ($DBI::err) : $DBI::errstr\n";
print qq~
<HTML><HEAD><TITLE>Areas</TITLE>
<BASEFONT FACE="Comic Sans MS, fantasy">
<HEAD>
<BODY BGCOLOR = "99CCFF" TEXT="330066" SIZE="5">
<TABLE ALIGN="center"> <CAPTION><H2>Here are your results <H2></CAPTION>
<TBODY><TR BGCOLOR="00ffff" TEXT="330066">
<TH>Code</TH>
<TH>Name</TH>
<TH>Length</TH>
<TD align ="center">$Code</TD>
<TD align ="center">$Name</TD>
<TD align ="center">$Hight</TD>
</TR>
while (@row = $query->fetchrow_array)
{
($Area) = @row;
print "<TD align ="center">$Code</TD>
<TD align ="center">$Name</TD>
<TD align ="center">$Hight</TD>
</TR>\n";
}
{
my ($Area) = @$row;
print $Code $Name $Hight" $\n";
}

$query->finish()or die "\n ($DBI::err) : $DBI::errstr\n";
$DBH->disconnect();

</TBODY>
</TABLE>
</BODY>
</HTML>~;


C:\Program Files\Apache Group\Apache2\cgi-bin>area_guide.pl [Tue Jan 20 10:09:03 2004] C:\Program Files\Apache Group\Apache2\cgi-bin\area_guide.pl: Possible unintended interpolation of @row in string at C:\Program Files\Apache Group\Apache2\cgi-bin\area_guide.pl line 12. Content-Type: text/html [Tue Jan 20 10:09:03 2004] C:\Program Files\Apache Group\Apache2\cgi-bin\area_guide.pl: Use of uninitialized value in concatenation (.) or string at C:\Program Files\Apache Group\Apache2\cgi-bin\area_guide.pl line 12.

</TR> while ( = DBI::st=HASH(0x1a3ca70)->fetchrow_array) { () = ; print "<TD align ="center"></TD> <TD align ="center"></TD> <TD align ="center"></TD> </TR> "; } { my () = ; print " n"; } DBI::st=HASH(0x1a3ca70)->finish()or die " () : "; DBI::db=HASH(0x1a3c980)->disconnect(); </TBODY> </TABLE> </BODY> </HTML>[Tue Jan 20 10:09:05 2004] C:\Program Files\Apache Group\Apache2\cgi-bin\area_guide.pl: Database handle destroyed without explicit disconnect.

Last edited by:

Andy: Jan 21, 2004, 2:40 AM
Quote Reply
Re: [Silver Machine] Use of uninitialized value in concatenation (.) or string In reply to
please use the CODE forum tag so that your code formatting is retained, and easier to read.

here's what I see, ignoring the error messages for now....

1) you never closed the first print call. add:
Code:
~;
before
Code:
while (@row = $query->fetchrow_array)

2)you use double-quote style print, but didn't escape double quotes. change:
Code:
print "<TD align ="center">$Code</TD>
<TD align="center">$Name</TD>
<TD align="center">$Hight</TD>
</TR>\n";
to
Code:
print "<TD align=\"center\">$Code</TD>
<TD align=\"center\">$Name</TD>
<TD align=\"center\">$Hight</TD>
</TR>\n";
or
Code:
print qq~<TD align="center">$Code</TD>
<TD align ="center">$Name</TD>
<TD align ="center">$Hight</TD>
</TR>\n"~;

3)$row is not defined, and the line appears redundant anway:
Code:
my ($Area) = @$row;

4)no opening double quote or quoting symbol, use of double quote before the end of the string, no such thing as $\n.
change:
Code:
print $Code $Name $Hight" $\n";
to:
Code:
print qq~$Code $Name $Hight \n~;


5) no opening print statement for final HTML output.
change:
Code:
</TBODY>
</TABLE>
</BODY>
</HTML>~;
to:
Code:
print qq~</TBODY>
</TABLE>
</BODY>
</HTML>~;

6) @row is assigned to $Area, but $Area is never used again. Values for $Code, $Name, and $Hight never change, even though it appears you mean to actually have them assigned to @row.

Philip
------------------
Limecat is not pleased.

Last edited by:

fuzzy logic: Jan 20, 2004, 7:17 AM
Quote Reply
Re: [Silver Machine] Use of uninitialized value in concatenation (.) or string In reply to
Thank you for your detailed explination I really need it. I still havent got it to work I just dont understand what how to define what ever I need to define. I have been looking around at various source material and all it has done is confuse me further. I have tried several other methods including foreach, I then got told to define my Objects and I didnt know what they were. I just cannot get my variables to go in to the table.

Code:
#!c:\perl\bin\perl.exe -w
print "Content-Type: text/html\n\n";
use strict;
use CGI::Carp qw(fatalsToBrowser);
my $Code=param("Code");
my $Name=param("Name");
my $Hight=param("Hight");
my $row=param("Row")
my $Sighting=param("Sighting")
use DBI;
my $DBH= DBI->connect ("DBI:mysql:Guide")or die "\n ($DBI::err) : $DBI::errstr\n";
my $sth = $DBH->prepare(qq~SELECT * FROM Area~)or die "\n ($DBI::err) :



$DBI::errstr\n";
$sth->execute()or die "\n ($DBI::err) : $DBI::errstr\n";
{qq~
<HTML><HEAD><TITLE>Areas</TITLE>
<BASEFONT FACE="Comic Sans MS, fantasy">
<HEAD>
<BODY BGCOLOR = "99CCFF" TEXT="330066" SIZE="5">
<TABLE ALIGN="center" WIDTH="75%" Height="75%"



BORDER="8"BORDERCOLOR="00ffff" BGCOLOR="c0ffff" CELLSPACING="10"

CELLPADDING="10" TEXT="330066"FONT FACE="Comic Sans MS,fantasy">

<CAPTION><H2>Here are your Areas <H2></CAPTION>
<TBODY><TR BGCOLOR="00ffff" TEXT="330066">
<TH>Code</TH>
<TH>Name</TH>
<TH>Hight</TH>
</TR>~;
while (my $Sighting = $sth->fetchrow_array);
{
print $Area qq~<TR><TD align ="center">$Code</TD>;
<TD align ="center">$Name</TD>;
<TD align ="center">$Hight</TD>;
</TR>\n"~;
};

$sth->finish()or die "\n ($DBI::err) : $DBI::errstr\n";
$DBH->disconnect();
qq~
</TBODY>
</TABLE>
</BODY>
</HTML>~;

this gives:


<HTML><HEAD><TITLE>Areas</TITLE>
<BASEFONT FACE="Comic Sans MS, fantasy">
<HEAD>
<BODY BGCOLOR = "99CCFF" TEXT="330066" SIZE="5">
<TABLE ALIGN="center">
<CAPTION><H2>Here are your results <H2></CAPTION>
<TBODY><TR BGCOLOR="00ffff" TEXT="330066">
<TH>Code</TH>
<TH>Name</TH>
<TH>Hight</TH>
<TR><TD align ="center"></TD>
<TD align ="center"></TD>
<TD align ="center"></TD>
</TR>Content-type: text/html

<H1>Software error:</H1>
<PRE>Can't use an undefined value as a symbol reference at C:/Program Files/Apache Group/Apache2/cgi-bin/area_sighting.pl line 29.
</PRE>
<P>
For help, please send mail to the webmaster (<a href="mailto:local@unn.ac.uk">local@unn.ac.uk</a>), giving this error message
and the time and date of the error.

If I change to this:

{
print
qq~<TD align="center">$Code</TD>
<TD align ="center">$Name</TD>
<TD align ="center">$Hight</TD>
</TR>\n"~;
}



I get the following which has the correct number of table rows inserted but also some wierd """. I would be very grateful if some one could explain what I am ment to do. Thanks Chris

<HTML><HEAD><TITLE>Areas</TITLE>
<BASEFONT FACE="Comic Sans MS, fantasy">
<HEAD>
<BODY BGCOLOR = "99CCFF" TEXT="330066" SIZE="5">
<TABLE ALIGN="center">
<CAPTION><H2>Here are your results <H2></CAPTION>
<TBODY><TR BGCOLOR="00ffff" TEXT="330066">
<TH>Code</TH>
<TH>Name</TH>
<TH>Length</TH>
<TR><TD align ="center"></TD>
<TD align ="center"></TD>
<TD align ="center"></TD>
</TR><TD align="center"></TD>
<TD align ="center"></TD>
<TD align ="center"></TD>
</TR>
"<TD align="center"></TD>
<TD align ="center"></TD>
<TD align ="center"></TD>
</TR>
"<TD align="center"></TD>
<TD align ="center"></TD>
<TD align ="center"></TD>
</TR>
"<TD align="center"></TD>
<TD align ="center"></TD>
<TD align ="center"></TD>
</TR>
"
"
</TBODY>
</TABLE>
</BODY>
</HTML>
Quote Reply
Re: [Silver Machine] Use of uninitialized value in concatenation (.) or string In reply to
I have managed to get the variables to display on the web page by using the following code. However they all clump together in the first row of the table. I tried calling them with their numbers [0] etc but then nothing printed at all. Any ideas please? Chris

Code:
while (@row = $sth->fetchrow_array) {
($list) = @row; print qq~<TD align ="center"> @row </TD></TR>~;
}
{
my ($list) = @$row;
print qq~<TR><TD align ="center">$list</TD>
<TD align ="center">$list</TD>
<TD align ="center">$list</TD>
</TR>\n"~;}
Quote Reply
Re: [Silver Machine] Use of uninitialized value in concatenation (.) or string In reply to
Is this what you're after?

Code:
while (my @row = $sth->fetchrow_array) {
print qq~<TR><TD align ="center">$_</TD></TR>~ foreach @row;
}

~Charlie
Quote Reply
Re: [Silver Machine] Use of uninitialized value in concatenation (.) or string In reply to
This may be a little closer:

Code:
#!/usr/bin/perl -w

use DBI;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $in = CGI->new;

my $Code = $in->param('Code');
my $Name = $in->param('Name');
my $Hight = $in->param('Hight');

my $dbh = DBI->connect('DBI:mysql:database=database;host=localhost',
'user', 'pass',
{'RaiseError' => 1,
'PrintError' => 1,
'ShowErrorStatement' => 1,
}) or die $DBI::errstr;

my $sth = $dbh->prepare(qq~SELECT * FROM table~);
$sth->execute;

print $in->header;
print qq~<HTML>
<HEAD>
<TITLE>Areas</TITLE>
<BASEFONT FACE="Comic Sans MS, fantasy">
</HEAD>

<BODY BGCOLOR = "99CCFF" TEXT="330066" SIZE="5">
<TABLE ALIGN="center">
<CAPTION><H2>Here are your results <H2></CAPTION>
<TBODY>
<TR BGCOLOR="00ffff" TEXT="330066">
<TH>Code</TH>
<TH>Name</TH>
<TH>Length</TH>
</TR>
<TR>
<TD align ="center">$Code</TD>
<TD align ="center">$Name</TD>
<TD align ="center">$Hight</TD>
</TR>$/~;

while (my @row = $sth->fetchrow_array) {
print "<TR>$/";
print qq~<TD align ="center">$_</TD>~ foreach @row;
print "</TR>$/";
}

print qq~ </TBODY>
</TABLE>
</BODY>
</HTML>~;
$dbh->disconnect;
Quote Reply
Re: [Silver Machine] Use of uninitialized value in concatenation (.) or string In reply to
Hi there thanks every one I am sorted now! Yesterday I was getting an oops message when I was trying to do things on this site any one know why. All it would let me do was edit profile. Very strange. Thanks for all the help again Chris