SamCG has asked for the wisdom of the Perl Monks concerning the following question:

I'm moving our company's ASP pages from VBS to Perlscript (for a variety of reasons, not all related to Perlscript's simpler interface for doing simple things and better overall power and compactness). Anyway, it seems to be ignoring my setting a variable's value. The code isn't extraordinarily long, so I'm posting all the relevant part here. In short, the $rtype variable, even though it seems to be "row", never gets to the elsif statement. Results can be seen at kbw.com. Forgive the current mess, I've put in a few statements to change the output so I could see what's going on. So far, it hasn't helped:
#First, set a bunch of semi-constants (apologies to those offended by +the lack of conventions here). $tdo = "<td>"; $tdc = "<\/td>"; $tblo = "<table width=\"525\" border=\"0\" cellpadding=\"5\" cellspaci +ng=\"0\">"; $hro = "<tr bgcolor=\"#0065ce\">"; $rc = "<\/tr>"; $ro = "<tr>"; $htd = "<td valign=\"top\"><b><font size=\"2\" color=\"white\" face=\" +Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">"; $htdc = "<\/font><\/b>".$tdc; ## Now the actual working code $time=0; $Response->write($tblo); ## Write table (works) $filename = $Server->MapPath('./data/test.dat'); ## map file open(fileREAD, $filename); #open file (works) while ($line = <fileREAD>){ $rtype = ""; @array = split "\t", $line; $rtype = pop @array; $time ++; $Response->write("<tr><td>line = ".$line."&".$rtype."&".$time."<\/td>< +\/tr>"); ## t-shoot #$Response->write("rtype = ".$rtype); if ($rtype = "header "){ $Response->write($hro); foreach (@array){ #$Response->write("<tr><td>line = ".$line."&".$rtype." +&".$time."<\/td><\/tr>"); $Response->write($htd.$_.$rtype.$htdc); #$Response->write("<tr><td>line = ".$line."&".$rtype." +&".$time."<\/td><\/tr>"); } } elsif ($rtype = "row "){ $Response->write($ro); foreach (@array){ $Response->write($td.$_.$tdc); } } $Response->write($rc);
Any help appreciated Thanks Sam

Replies are listed 'Best First'.
Re: Perlscript ASP page responds strangely
by meetraz (Hermit) on Nov 11, 2003 at 23:38 UTC
    In your if's and elsif's you are using the single "=" sign when you mean to use the double "==" sign.

    The single "=" is for setting a variable, while the "==" is for checking equality.

    In addition, when checking for string equality, you should use "eq" instad of "==".

    You probably got confused because VBscript uses "=" for everything.

Re: Perlscript ASP page responds strangely
by Roger (Parson) on Nov 11, 2003 at 23:56 UTC
    moving our company's ASP pages from VBS to Perlscript

    Ah... A classic gotchya.
    if ($rtype = "header ")
    should be changed to
    if ($rtype eq "header ")
    instead. The '=' sign in the VB 'if' means equality test, but in Perl is an assignment. And also because you are comparing are two strings, you should use the 'eq' comparison keywords.