LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-01-2009, 09:41 AM   #1
haxpak
Member
 
Registered: Jan 2009
Location: India
Distribution: fc9 x86_64
Posts: 35

Rep: Reputation: 15
please help me with this perl code getting error "use of uninitialized value"


hi
i am getting error as:
Use of uninitialized value in concatenation (.) or string at ./iothread.pl line 86, <GEN1> line 1.
during runtime

and
the output looks like this:
Quote:
Multiplex server running on port 4444...
Created thread 1 for new client 10.168.1.2:3233
Use of uninitialized value $_ in scalar chomp at ./iothread.pl line 66, <GEN1> line 1.
1005874632400418
1234
login

Use of uninitialized value in concatenation (.) or string at ./iothread.pl line 86, <GEN1> line 1.
10895
Thread 1 terminated abnormally: Not a CODE reference at ./iothread.pl line 87, <GEN1> line 1.
Code:
#!/usr/bin/perl
# iothreadserv.pl
use warnings;
use strict;
use integer;

BEGIN 
	{
	use Config;
	die "No thread support!\n" unless $Config{'usethreads'};
	}

use Thread;
use IO::Socket;
use DBI;
use DBD::mysql;

# Autoflushing on
$| = 1;
my $port = 4444;
my $server = IO::Socket->new(
	Domain    => PF_INET,
	Proto     => 'tcp',
	LocalPort => $port,
	Listen    => SOMAXCONN,
	Reuse     => 1,
);

die "Bind failed: $!\n" unless $server;
print "Multiplex server running on port $port...\n";

while (my $connection = $server->accept) 
	{
	my $name = $connection->peerhost;
	my $port = $connection->peerport;
	my $thread = new Thread(\&connection, $connection, $name, $port);
	print "Created thread ",$thread->tid," for new client $name:$port\n";
	$thread->detach;
	}
exit;


# child thread - handle connection
sub connection 
{
	my ($connection, $name, $port) = @_;
	$connection->autoflush(1);
	#############################my sql connect###############################
	my $platform = "mysql";
	my $database = "project";
	#my $host = "localhost";
	#my $port = "3306";
	my $user = "root";
	my $pw = "";
	
	# DATA SOURCE NAME
	my $dsn = "dbi:mysql:$database";
	
	# PERL DBI CONNECT
	my $dbh = DBI->connect($dsn, $user, $pw) or die "cannot connect to database";
	
	#######################################################################33

	print $connection "You're connected to the server!\n";
	my $client = <$connection>;
	chomp; # ($client);
	#while (<$connection>) {
	if ($client =~ /::login/)
	{
		print $connection "Login Initiated\n";
		my $rand = int(rand(100000));
		print $connection "Your rand number : $rand";
		#$client =~ s/([\$\@\\])/\\$1/mg; ##escape all $, @ and \
		#$client = quotemeta $client;
		my @recv_string = split /::/ , $client;
		foreach (@recv_string)
		{
		print "$_ \n";
		}
		#next line injection possible !! REMOVE IT!!
		my $sth = $dbh->prepare("select * from Temp_ID where TEMP_NO = $recv_string[0]");
		$sth->execute();
		#take only one output row
		my $ref = $sth->fetchrow_hashref();	
#		$sth->finish();
		print "$ref->{'Temp_ID'} $ref->{'CARD_ID'}\n";
		$sth = $dbh->("select PIN from Cards where Card_ID = $ref->{CARD_ID}");
		$sth->execute();
#		$sth->finish();
		
		my $ref2 = $sth->fetchrow_hashref();
		if ($recv_string[1] eq $ref2->{PIN})
			{
			print $connection "PIN verified OK";
			
			}
			
		
	}
	
	if ($client =~ /:logout/)
	{
		print $connection "You are being Logged OUT\n";
	}
	print "Client $name:$port says: $client \n";
      	print $connection "Message received OK\n";
	#	}
	$dbh->disconnect;
	$connection->shutdown(SHUT_RDWR);
}
 
Old 03-01-2009, 11:10 AM   #2
haxpak
Member
 
Registered: Jan 2009
Location: India
Distribution: fc9 x86_64
Posts: 35

Original Poster
Rep: Reputation: 15
please all ppl out there hel me
i am stuck
 
Old 03-01-2009, 11:10 AM   #3
haxpak
Member
 
Registered: Jan 2009
Location: India
Distribution: fc9 x86_64
Posts: 35

Original Poster
Rep: Reputation: 15
please all ppl out there hel me
i am stuck
 
Old 03-01-2009, 11:47 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Well, if it says:
Code:
Use of uninitialized value $_ in scalar chomp at ./iothread.pl line 66, <GEN1> line 1.
then you'd better look at line 66, right?

Line 66 looks like this:
Code:
        chomp; # ($client);
What do you expect that line to do for you? What purpose does it serve in your program?
 
Old 03-01-2009, 04:58 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by wje_lq View Post
Well, if it says:
Code:
Use of uninitialized value $_ in scalar chomp at ./iothread.pl line 66, <GEN1> line 1.
then you'd better look at line 66, right?

Line 66 looks like this:
Code:
        chomp; # ($client);
What do you expect that line to do for you? What purpose does it serve in your program?
I would even ask a more particylar question: "What's the argument of 'chomp' ?".
 
Old 03-01-2009, 05:03 PM   #6
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Quote:
I would even ask a more particylar question: "What's the argument of 'chomp' ?".
In his code, it doesn't have one. But Perl doesn't require that it have one. That's why I'm asking him what he thinks the statement is supposed to do for him.
 
Old 03-01-2009, 05:15 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by wje_lq View Post
In his code, it doesn't have one. But Perl doesn't require that it have one. That's why I'm asking him what he thinks the statement is supposed to do for him.
Well, if a function doesn't have an argument (but it's not the case), then what does it do ?

Burns CPU time ? Changes a global variable randomly ?
 
Old 03-01-2009, 08:26 PM   #8
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
This would be an interesting discussion to have at some point, but right now I'm mainly interested in what haxpak's intention was on line 66. haxpak? You still there?
 
Old 03-01-2009, 10:11 PM   #9
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by wje_lq View Post
This would be an interesting discussion to have at some point, but right now I'm mainly interested in what haxpak's intention was on line 66. haxpak? You still there?
I don't think there is a place for discussion, but I do think it's worth reading the manual. What about

perldoc -f chomp

?

My question about 'chomp' argument was a very practical one.
 
Old 03-01-2009, 11:01 PM   #10
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 809

Rep: Reputation: 178Reputation: 178
Quote:
My question about 'chomp' argument was a very practical one.
I never doubted your intention.

So. haxpak, you still there?
  1. As Sergei Steshenko would ask:
    Quote:
    What's the argument of 'chomp' ?
  2. As I would ask: what's your intention with line 66?
    Code:
            chomp; # ($client);
 
Old 03-01-2009, 11:55 PM   #11
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
I agree with this line of reasoning: "what is your intention," and, "do you know what your intention is?"

This isn't a "slam" ... isn't public humiliation ... it's necessary in really understanding and solving any problem.

Perl has many "implied arguments," in this case as in many other cases (see perldoc perlvar), which can make it cryptic. But if you can first latch upon the designer's intent, whether "the designer" is you or someone else, the nature of any logic error usually reveals itself quickly.

I would urge you to respond: this is the help you are asking for. Participate. (Others are watching intently.)

Last edited by sundialsvcs; 03-01-2009 at 11:56 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Failed Dependency error" while installing RPM for "DateTime" perl modules giridhargopal.cj Linux - Newbie 7 11-19-2008 01:05 AM
perl install error: Can't locate object method "new" via package "Module::Build::Vers powah Linux - Software 0 10-24-2006 02:57 PM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 05:51 AM
Synaptic error: "sub-process /usr/bin/dpkg returned an error code (2)" firefly2442 Linux - Software 3 02-04-2004 07:41 PM
LFS 4.1: Stalled at Perl, "missing seperator" error from "make" SparceMatrix Linux From Scratch 1 06-07-2003 04:31 PM


All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration