[thelist] Perl If, Elsif Statements

dave at stemfiction.com dave at stemfiction.com
Sun Feb 22 12:38:01 CST 2004


Hello again,

I have the following code in a loop for each line of an existing text
file containing tab separated data. It reads each bit of info in to the
relevant variable, and then I'm testing it for certain criteria. the
first if statement below works fine - if all the variables posted to it
from the browser ($students, $roompref, etc) match the variables from
the file, the subroutine writeit() is called which writes them to a file
that is later used to display the results. 

However, I'm stuck as to how to proceed to allow the user to specify
just one or maybe a couple of criteria and have them displayed. I had
individual ones working by having long if statements which said
(pseudocode) if postedvariable = storedvariable and othervar1 = "" and
othervar2 = "" etc etc then do writeit(). 

So sorry for any vagueness, but any and all help is appreciated!

The Code Snippet:

($site,$size,$room,$DP,$OHP,$Wheelchair) = split(/\t/,$line);
if ($size >= $students && $room eq $roompref && $site eq $parkpref &&
$DP eq $dataproj && $OHP eq $ohproj && $Wheelchair eq $wchair) {
       
      do writeit();

    } elsif ($size >= $students || $room eq $roompref || $site eq
$parkpref || $DP eq $dataproj || $OHP eq $ohproj || $Wheelchair eq
$wchair) {
       
      do writeit();

}

Cheers
Dave


More information about the thelist mailing list