Fun with Perl subject logo: UNIX
2009-10-06
Posted by: badanov

I just finished resolving a vexing problem in a perl CGI script:

if ( $test eq'TESTDATA' )
{
$dresult='<option value="PositiveResult">Positive Result';
}
elsif ( $test ne'TESTDATA' )
{
$dresult='<option value="NegativeResult">Negative Result';
}

In the above example, the plugged in html code $dresult printed the first result regardless of what the value of $test was.

The solution was to make the perl script extract a part of the string, since various forms of $test existed.

Not certain why this worked, except perhaps since this script was executed by the Apache mod_perl module and not directly by the perl interpreter, perl may have "forgotten" it was the primary thread in this process, and failed its instructions.

Forcing the script to do a native, fundamental perl function, extract a string, I was able to make the script work as desired.

Solution:

$test = 'TESTDATA';
$test2 = ( substr $test, -5 );
f ( $test2 eq'TDATA' )
{
$dresult='<option value="PositiveResult">Positive Result';
}
elsif ( $test2 ne'TDATA' )
{
$dresult='<option value="NegativeResult">Negative Result';
}

I don't know if extracting the whole string would work, but there is little doubt that it would.

If you have something to add, Fire Away!

Number of Comments so far: 0

Click here for a list of stories in the Unix and Computer category