Hi Rob Thank you for all valuable informations. I tried all the steps you mentioned in the mail. All were success except only following lines.
my $sth = $dbh->prepare($query) or die $dbh->errstr; $sth->execute($ip) or die $dbh->errstr; if i add those lines in to the code , squid redirector doesnt work and gives following error message, 2008/07/15 14:26:46| clientRedirectDone: 'http://www.goog.com' 2008/07/15 14:26:46| WARNING: redirector #1 (FD 6) exited anyway i again i wanted to monitor the behaviors of the perl code and i'll let you know the status. as you know , does mysql switch to a idle mode or sleep mode , coz just for testing i don't send many request at a time. just a single test request made for the servers. Thank you Luke ----- Original Message ---- From: Rob Dixon <[EMAIL PROTECTED]> To: Perl <beginners@perl.org> Cc: luke devon <[EMAIL PROTECTED]> Sent: Monday, July 14, 2008 23:27:21 Subject: Re: Perl script doesnt behave well luke devon wrote: > > I am using perl script to handle some function of squid redirector program . > Actually its working fine. But after some time , that functions goes off. > That's meant VALUE-A doesnt comes in to the request. > > I checked the DB , it also fine. > CPU also nothing > > Can some body help me please ? > > > > #!/usr/bin/perl > use DBI; > use strict; > use warnings; > > # no buffered output, auto flush > $|=1; > > my ($dbh,$sth,$dbargs,$VALUE-A,$VALUE-B,$query); It is best to declare variables at their point of first use, unless a greater scope is necessary, as for $VALUE-A and $VALUE-B, for which see below. > $dbh = DBI->connect("dbi:mysql:List;localhost","root","") || "Error Opening > DataBase: $DBI::errstr\n"; my $dbh = DBI->connect("dbi:mysql:List;localhost","root","") or die "Error Opening DataBase: $DBI::errstr" > if (!$dbh->err()) { If you test the success of the connect, above, then this test will always succeed and there is no need for it. In any case if there is a problem then $dbh will not be a valid database handle and so won't have an err method. > while (<STDIN>) { > chomp; > my ($url, $x, $ip) = split(/ /); my ($url, $x, $ip) = split; is better. > $ip = substr($ip, 0, (length($ip)-2)); Having read your previous posts about how to extract an IP address from a string, I believe this should be written ($ip) = $ip =~ /([0-9.]+)/; and may be the source of your problem if there are not always two characters of junk data after the IP address. > $query = "SELECT * from ACCOUNT where someField = '" . $ip ."' order > by xxx_yyy desc"; > $sth = $dbh->prepare($query); > $sth->execute(); my $query = "SELECT * from ACCOUNT where someField = ? order by xxx_yyy desc"; my $sth = $dbh->prepare($query) or die $dbh->errstr; $sth->execute($ip) or die $dbh->errstr; The scalar variables $VALUE-A and $VALUE-B should also be declared here, and ideally have more descriptive names. my ($VALUE-A, $VALUE-B); > if (my $ref = $sth->fetchrow_hashref()) { > $VALUE-A = $ref->{'CallingStationId'}; > $VALUE-B = $ref->{'AcctSessionId'}; > > }else{ > $VALUE-A = "NA"; > } At this point you may have a value of 'NA' for $VALUE-A and $VALUE-B could be either undefined or, worse, have a value left over from the previous execution of the read loop. I think you should just write next unless my $ref = $sth->fetchrow_hashref; $VALUE-A = $ref->{'CallingStationId'}; $VALUE-B = $ref->{'AcctSessionId'}; > if (!($url =~ m#xxxyyyy#)) { > if ($url =~ m#\?#) { > $url .= "&xxxyyyy=" . $VALUE-A . "-" . $ip . "-" . $VALUE-B; > } else { > $url .= "?xxxyyyy=" . $VALUE-A . "-" . $ip . "-" . $VALUE-B; > } > print $url."\n"; > } else { > print "\n"; > } > } > }else { > print "\n"; It seems appropriate to do something more than just print a blank line if your connection to the database failed. > } > $sth->finish(); > $dbh->commit(); > > $dbh->disconnect(); HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Send instant messages to your online friends http://uk.messenger.yahoo.com