我已經搜索了,直到我用完了選項。我一定在做錯事,但我搞不清楚是什麼。 (顯然,我是Perl新手,繼承了這個項目)。 我只是想看看一個變量是否等於'Y'。正如你可以看到下面的代碼底部,我已經嘗試'eq','='和'=='。除了設置等於'eq'操作結果的新變量外,所有嘗試都會導致頁面被炸燬。字符串測試($ stringtest)的結果看起來是空的,如果不是,我不知道如何測試它。我如何使用Perl比較兩個字符串
#!/usr/bin/perl -w
#######################################################################
# Test script to show how we can pass in the needed information
# to a web page and use it to run a program on the webserver and
# redirect its output to a text file.
#######################################################################
require 5; #Perl 5 or greater
require "jwshttputil.pl";
require "jwsdbutil.pl";
# Parse QUERY_STRING
&HTTPGet;
# Parse POST_STRING - NOTE: This CLEARS the post data
&HTTPPost;
print STDOUT "Content-type: text/html\n\n";
print STDOUT "<HTML><BODY>";
$canrun = "Y";
$is4ge = $Data{'is4ge'};
$sYes = "Y";
#Step 1: Check for needed values
if (!($Data{'user'}))
{
print "user was not found<br/>";
$canrun = "N";
}
if (!($Data{'pwd'}))
{
print "pwd was not found<br/>";
$canrun = "N";
}
if (!($Data{'is4ge'}))
{
print "is4ge was not found<br/>";
$canrun = "N";
}
print "$Data{'is4ge'}"; #prints Y
print $is4ge; #prints Y
if (!($Data{'db'}))
{
print "db was not found<br/>";
#if (!($is4ge = "Y")) #dies
# $canrun = "N";
#if (!($is4ge eq "Y")) #dies
# $canrun = "N";
#$stringtest = ($is4ge eq $sYes);
#print $stringtest; #displays nothing
#if (($is4ge == $sYes)) #dies
# $canrun = "N";
}
print STDOUT "</BODY></HTML>";
這段代碼幾乎和我一樣古老。這讓我害怕。 – simbabque
'if($ foo eq'Y'){print「foo is y \ n」; ''是你所需要的。 '$ is4ge =「Y」'總是'「Y」'。比較非數字需要'eq'。你說它死了。什麼是錯誤信息? – simbabque
'if(!($ is4ge =「Y」))'在這裏您將Y分配給$ is4age並且使其成爲「true」 - 賦值成功。 '=='測試兩件事是否「相等」。在這種情況下,你最好使用'if($ is4ge ne'Y')' - 一個字符串比較。但是,正如@simbabque提到的那樣,看不出爲什麼會死,或者下一次測試會死。你的意思是它沒有結果,什麼都不打印? – cbmckay