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/