MTputerman
Technical User
I'm reviving a previous post...I let it die but still need to work on the problem.
I have written this script:
The problem is that the sub never returns zeros that I enter. ie entering 1010 would return 11.
justice41 (member) had this reply:
what does the collect() subroutine look like? this is probably where the problem is. A zero evaluates to false so if a variable holds a zero and is evaluated in boolean context (as in an if statement) then the statement returns false even though the variable holds a valid value.
Posting the collect() subroutine would be helpful in tracking down the problem.
Here is where the previous post died. Here is the code:
I was wondering if I should force the function to int? I'm going to try it, but don't want to do it without some advice from a Perl 'superior'!
Thanks lots,
Scott
I have written this script:
Code:
sub getit()
{
# $value = "";
foreach (1..9)
{
$input = $ctport->collect(1,10); # get 1 digit...zeros get collected,
but don't get assigned to variable
$ctport->play("$input"); # echo the digit...zeros don't echo
$value .= $input;
next;
}
$value; # return value
The problem is that the sub never returns zeros that I enter. ie entering 1010 would return 11.
justice41 (member) had this reply:
what does the collect() subroutine look like? this is probably where the problem is. A zero evaluates to false so if a variable holds a zero and is evaluated in boolean context (as in an if statement) then the statement returns false even though the variable holds a valid value.
Posting the collect() subroutine would be helpful in tracking down the problem.
Here is where the previous post died. Here is the code:
Code:
/*--------------------------------------------------------------------------*
FUNCTION....: ctcollect
AUTHOR......: David Rowe
DATE CREATED: 10/10/01
Collect digits handler.
\*--------------------------------------------------------------------------*/
void ctcollect(int h, int newSd) {
char s[VPB_MAX_STR];
int state, ret, rc;
char line[MAX_MSG];
VPB_EVENT e;
int digits;
char buf[VPB_MAX_STR];
// read digits
memset(line,0x0,MAX_MSG);
read_line(newSd,line);
digits = atoi(line);
// read time out in seconds
memset(line,0x0,MAX_MSG);
read_line(newSd,line);
int unsigned long seconds = atol(line);
// read inter digit time out in seconds
memset(line,0x0,MAX_MSG);
read_line(newSd,line);
int unsigned long inter_seconds = atol(line);
VPB_DIGITS d = {"", digits, seconds*SEC2MS, inter_seconds*SEC2MS};
vpb_get_digits_async(h, &d, buf);
state = 0;
do {
ret = vpb_get_event_ch_async(h, &e);
if (ret == VPB_OK)
{
vpb_translate_event(&e, s); s[strlen(s)-1]=0;
mylog(LOG_INFO,"%s",s);
if (e.type == VPB_DIGIT)
{
state = 1;
sprintf(s, "%s\n", buf);
rc = send(newSd, s, strlen(s)+1, 0);
}
if (e.type == VPB_TONEDETECT)
{
if(e.data == VPB_BUSY)
{
state = 1;
rc = send(newSd,"\n", strlen("\n")+1, 0);
}
}
} // endof if(ret == VPB_OK)
else
vpb_sleep(100);
} while(!state);
}
I was wondering if I should force the function to int? I'm going to try it, but don't want to do it without some advice from a Perl 'superior'!
Thanks lots,
Scott