Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable losing its value - Very Odd.

Status
Not open for further replies.

Shadiman

Programmer
Jan 30, 2006
5
US
Dear All,

I'm taking input from a Serial Port.

#
# open the logfile, and Port
#

open(LOG,">>${LOGDIR}/${LOGFILE}")
||die "can't open smdr file $LOGDIR/$LOGFILE for append: $SUB $!\n";

open(DEV, "<$PORT")
|| die "Cannot open $PORT: $_";

select(LOG), $| = 1; # set nonbufferd mode

#
# Loop forver, logging data to the log file
#

while($_ = <DEV>){
($t,$Extn,$Trunk,$Dialed,$Digits,$Start_time,$Elaspesd_time,$Cost,$Account_Code)

$dbh ->do("INSERT INTO test (TYP,EXTN,DIGITS) VALUES ('$t','$Extn','$DIGITS')");

print LOG "Type = $t | Extn = $Extn | $Trunk | $Dialed | $Digits |$Start_time |$Elapsed_time |$Cost |$Account_Code\n";
}

undef $ob;

My problem is that the variable $t is behaving very odd !

I see the output in the LOG file i.e. print LOG "Type = $t and I can add an additional line to print $t. However if I try and send the value to the MySQL DB. I get the first entry and then all other values of $t are blank ! and yet the value appears in the LOG?

Also if I try and do an if statment on the $t value it works the first time and again it loses its value.

I restart the script and the same...

I'm at loss... any ideas?

Thanks

Shad Mortazavi
I just cant work out why this is?
 
Sorry the bit in the line in the middle should read;

($t,$Extn,$Trunk,$Dialed,$Digits,$Start_time,$Elaspesd_time,$Cost,$Account_Code) = split ;
 
try putting "my" in front of the list:

Code:
my($t,$Extn,$Trunk,$Dialed,$Digits,$Start_time,$Elaspesd_time,$Cost,$Account_Code) = split;

that way $t will have to be redefined each time through the loop. Are you sure you want to use split with no arguments? I believe it will split on spaces by default that way.
 
Kevin. Thanks.

I do want to split on space.

I have since tracked down the problem. There are some extra charecters that are comming over the serial port. If I open up the log file I gate @^@^@^@^@^@^@^DID etc.

I now need to work out how to remove them to clean up my input.

Again I would welcome any suggestions.

Warm Regards

Shad
 
which are the extra characters to get rid of and which do you want to keep?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top