At 01:23 07.06.2001 -0500, you wrote:
>How can I get this code to be more readable? Thanks in advance.
I would start with adding line breaks and tabs
#LOOP TO INITIALIZE VARIABLES + TEST N COMMANDS FOR MATCH IS YES
foreach $i (sort(@indata))
{
chop($i);
($aptname,
$address,
$city,
$zip,
$phone,
$location,
$bedrooms,
$rentmin,
$rentmax,
$pets,
$laundry,
$garage,
$comment,
$aptweb,
$aptemail,
$graphic) = split (/\|/, $i);
# this is rather convoluted, I would consider breaking it up into
multiple ifs, or a switch or something just to make it more legible -
unless it works and you'll *never* change it again, in which case you could
get away with leaving it -- though it is a rather ugly bit of code :)
if(($in{'location'} eq "All" || $location =~ /$in{'location'}/ig)
&& ($in{'bedrooms'} eq "Any" || $bedroom s=~ /$in{'bedrooms'}/ig ||
($in{'bedrooms'} eq "4 plus Bedrooms" && ($bedrooms=~/4 Bedrooms/ig ||
$bedrooms=~/5 Bedrooms/ig || $bedrooms=~/6 Bedrooms/ig))) &&
($rentmin<=$in{'rentmax'} && $rentmax>=$in{'rentmin'}) &&
($pets=~/$in{'pets'}/ig || $in{'pets'} eq "Doesn't Matter" ||
($in{'pets'}=~/yes/ig && ($pets=~/Cats/ig || $pets=~/Some Units/ig))) &&
($laundry=~/$in{'laundry'}/ig || $in{'laundry'} eq "Doesn't Matter" ||
($in{'laundry'}=~/yes/ig && $laundry=~/Some Units/ig)) &&
($garage=~/$in{'garage'}/ig || $in{'garage'} eq "Doesn't Matter" ||
($in{'garage'}=~/yes/ig && $garage=~/Some Units/ig)))
{
$match = "yes";
$apartment++;
# here you can use qq~
print qq~
<tr><td rowspan=\"5\"><img src=\"$url/aptimages/$graphic\"
height=\"150\" width=\"150\" hspace=\"10\" alt=\"Apartment Graphic\"><td
colspan=\"2\"><br></td></tr>
<tr><td colspan=\"2\"><b><i>Result</i></b>: $apartment
</td></tr>
<tr><td><a
href=\"http:/$aptweb\">$aptname</a><br>$address<br>$city
$zip<br>$phone<br><a
href=\"$url$urlcgi/aptemailhtml.cgi?aptemail=$aptemail&aptname=$aptnam
e&phone=$phone\">Contact Us</a></td><td width=\"350\"
valign=\"top\"><i><b>Rent</b></i>: $rentmin to
$rentmax<br><i><b>Bedrooms</b></i>: $bedrooms</td>
</tr>
<tr><td><b><i>Pets:</i></b> $pets <b><i>Laundry:</i></b>
$laundry <b><i>Garage:</i></b> $garage</td><td><br></td>
</tr>
<tr><td><b><i>Hyde Park Location:</i></b>
$location</td><td><br></td>
</tr>
<tr><td colspan=\"2\"><b><i>Comments:</i></b>$comment</td>
</tr>
~;
}
}
print "</table>\n";
Aaron Craig
Programming
iSoftitler.com