Gossamer Forum
Home : General : Perl Programming :

Use of uninitialized value in concatenation (.) or string

Quote Reply
Use of uninitialized value in concatenation (.) or string
Hi All..

I am facing the following error...

"Use of uninitialized value in concatenation (.) or string at creategroup_check.cgi line 26."

while running the below script...

#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Session;
use DBI;

my $query=new CGI;
my $cgiobj=CGI -> new();
#print "Content-type:text/plain\n\n";

my $username = $cgiobj -> param('username');
my $groupname = $cgiobj -> param('groupname');
#my $db_groupname;

my $session = new CGI::Session(undef,$query, {Directory => '/tmp'});
my $sid = $session->id();
#print $sid;
$session -> param('username',$username);

$ENV{ORACLE_HOME}="/home/oracle/product/10.2.0/db_1";
our $conn = DBI->connect("dbi:Oracle:host=10.0.0.1;sid=dev;","queryeditor","editor");
die($DBI::errstr) unless $conn;

my $user_detail = "select * from qe_group where groupname='$groupname'";
my $user_records = $conn->prepare($user_detail) or die("Error on preparing the sql statement \n");
$user_records->execute() or die("Error on getting the data from QE_GROUP \n");
while(my @user_resultset= $user_records->fetchrow_array)
{
my $db_groupname = $user_resultset[1];
print $db_groupname;
}


Any Idea on this ?

Thanks,
Warm Regards,
Saravanan
Quote Reply
Re: [slg_saravanan] Use of uninitialized value in concatenation (.) or string In reply to
Hi,

Not sure - but it may be something to do with (it may be ok how you have it, but it looks a bit odd, and its not really a good practice to get into ,as you end up confusing yourself when going over old code ;))

Code:
my $username = $cgiobj -> param('username');
my $groupname = $cgiobj -> param('groupname');

..doesn't look like valid syntax :P

Think it should be more like:

Code:
my $username = $cgiobj->param('username');
my $groupname = $cgiobj->param('groupname');

Same with:

Code:
$session -> param('username',$username);

..should be more like:

Code:
$session->param('username',$username);

Also, why do you use "our $conn" ? "my" would be better.

Here is how I think the code should look;

Code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Session;
use DBI;

my $IN=new CGI;
#print "Content-type:text/plain\n\n";

my $username = $IN->param('username');
my $groupname = $IN->param('groupname');
#my $db_groupname;

my $session = new CGI::Session(undef,$query, {Directory => '/tmp'});
my $sid = $session->id();

$session->param('username',$username);

$ENV{ORACLE_HOME}="/home/oracle/product/10.2.0/db_1";
my $conn = DBI->connect("dbi:Oracle:host=10.0.0.1;sid=dev;","queryeditor","editor");
die($DBI::errstr) unless $conn;

my $user_detail = qq|select * from qe_group where groupname='$groupname'|;
my $user_records = $conn->prepare($user_detail) || die("Error on preparing the sql statement \n");
$user_records->execute() || die("Error on getting the data from QE_GROUP \n");
while(my @user_resultset= $user_records->fetchrow_array) {
my $db_groupname = $user_resultset[1];
print $db_groupname;
}

Hope that helps somewhat :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Use of uninitialized value in concatenation (.) or string In reply to
Hi Andy,

Thanks..But..

Still..am getting same error...I think this is an simple record fetch program..what could be the wrong with the code ?

error shows @ 25th line ...that is "my $user_detail = qq|select * from qe_group where groupname='$groupname'|;"



Warm Regards,
Saravanan
Quote Reply
Re: [slg_saravanan] Use of uninitialized value in concatenation (.) or string In reply to
Hi,

Not sure :/

$DBI::errstr should catch it.

One thing I'm not totally sure about, is:

"dbi:Oracle:host=10.0.0.1;sid=dev;"

Try it as:

"dbi:Oracle:host=10.0.0.1"

Try this way, and see if you get anything different:

Code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Session;
use DBI;

my $IN=new CGI;
#print "Content-type:text/plain\n\n";

my $username = $IN->param('username');
my $groupname = $IN->param('groupname');
#my $db_groupname;

my $session = new CGI::Session(undef,$query, {Directory => '/tmp'});
my $sid = $session->id();

$session->param('username',$username);

$ENV{ORACLE_HOME}="/home/oracle/product/10.2.0/db_1";
my $conn = DBI->connect("dbi:Oracle:host=10.0.0.1;sid=dev;","queryeditor","editor") || die $DBI::errstr;

my $user_detail = qq|select * from qe_group where groupname='$groupname'|;
my $user_records = $conn->prepare($user_detail) || die $DBI::errstr;
$user_records->execute() || die $DBI::errstr;
while(my @user_resultset= $user_records->fetchrow_array) {
my $db_groupname = $user_resultset[1];
print $db_groupname;
}

I guess if that still doesn't work, try removing bits of code at the end, and see if you get the errors... i.e start with just the basics:

Code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Session;
use DBI;

my $IN=new CGI;
#print "Content-type:text/plain\n\n";

my $username = $IN->param('username');
my $groupname = $IN->param('groupname');
#my $db_groupname;

my $session = new CGI::Session(undef,$query, {Directory => '/tmp'});
my $sid = $session->id();

$session->param('username',$username);

$ENV{ORACLE_HOME}="/home/oracle/product/10.2.0/db_1";
my $conn = DBI->connect("dbi:Oracle:host=10.0.0.1;sid=dev;","queryeditor","editor") || $DBI::errstr;

..and if that works ok, then that code should be fine... then that at least narrows it down a bit as to exactly what code could be causing the problem.

Also, it may be worth "dumping" the value of $conn, to see what it contains - i.e:

Code:
my $conn = DBI->connect("dbi:Oracle:host=10.0.0.1;sid=dev;","queryeditor","editor")
use Data::Dumper;
print q|DUMP OF $conn: | . Dumper($conn);

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Use of uninitialized value in concatenation (.) or string In reply to
I'm surprised that a "Veteran" and plugin author is unable to debug the most basic error message. I've been lurking for a few weeks and can't bare not responding any longer.

Code:
$DBI::errstr should catch it.




No it won't, it has nothing to do with DBI, it's a standard perl error message relating to uninitialized variables within strings.

Quote:
Also, why do you use "our $conn" ? "my" would be better.



Why?....what if $conn is being used within another package?

It sounds like you are giving answers without understanding what you are saying.

The error, as is clearly described, states that a value being used in a concatenation or string is uninitialized. Line 26 according to my editor is:

Code:
my $user_detail = "select * from qe_group where groupname='$groupname'";

Last edited by:

Wychwood: May 7, 2007, 5:05 PM
Quote Reply
Re: [Wychwood] Use of uninitialized value in concatenation (.) or string In reply to
Hi,

Quote:
my $user_detail = "select * from qe_group where groupname='$groupname'";

Erm, well excuse my ignorance, but where the heck is that problem with the line? There is no concatenation!

Unless its the * causing a problem? (which I would be very amazed at)

Quote:
Why?....what if $conn is being used within another package?

Well, in that case fair enough - which is why I asked WHY he was using "our" instead of "my" Wink

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Use of uninitialized value in concatenation (.) or string In reply to
Quote:
Erm, well excuse my ignorance, but where the heck is that problem with the line? There is no concatenation!

Use of uninitialized value in concatenation (.) or string
Quote Reply
Re: [Wychwood] Use of uninitialized value in concatenation (.) or string In reply to
Wychwood wrote:
Use of uninitialized value in concatenation (.) or string

You've lost me - $groupname is the only variable (apart from the declaration of $user_detail), but that is defined further up:

Code:
my $groupname = $IN->param('groupname');

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Use of uninitialized value in concatenation (.) or string In reply to
Quote:
You've lost me - $groupname is the only variable ..., but that is defined further up:


Not necessarily. Try running this code...

Edit: Ok, so attachments don't seem to be working. The code is:

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

use CGI;

main();

sub main {
my $cgi = CGI->new;
my $var = $cgi->param('null');
my $str = "This is a test string: $var";
print defined $var ? 1 : 0;
}

Last edited by:

Wychwood: May 8, 2007, 5:17 PM
Quote Reply
Re: [Wychwood] Use of uninitialized value in concatenation (.) or string In reply to
 

Hello all..Thanks for your help !

I fixed out that problem !!

Cheers !!

Saravanan..Smile