I'm doing a really repetitive function here and I wondered how I might be able to simplify it. Any ideas? Here's the code:
if ($file1 ne "") { push @tour_photos, ($file1); } if ($file2 ne "") { push @tour_photos, ($file2); } if ($file3 ne "") { push @tour_photos, ($file3); } if ($file4 ne "") { push @tour_photos, ($file4); } if ($file5 ne "") { push @tour_photos, ($file5); } if ($file6 ne "") { push @tour_photos, ($file6); } if ($file7 ne "") { push @tour_photos, ($file7); } if ($file8 ne "") { push @tour_photos, ($file8); } if ($file9 ne "") { push @tour_photos, ($file9); } if ($file10 ne "") { push @tour_photos, ($file10); }
I've also got some huge lists of variables to accept from a cgi program and I wondered if there were an easier way to do this too:
$address = $cgi->param('ADDRESS'); $bedrooms = $cgi->param('BEDROOMS'); $baths = $cgi->param('BATHS'); $garage = $cgi->param('GARAGE'); $roof = $cgi->param('ROOF'); $architectural_style = $cgi->param('ARCHITECTURAL_STYLE'); $floorplan = $cgi->param('FLOORPLAN'); $flooring = $cgi->param('FLOORING'); $heating = $cgi->param('HEATING'); $acreage = $cgi->param('ACREAGE'); $lot_dimensions = $cgi->param('LOT_DIMENSIONS'); $view = $cgi->param('VIEW'); $water_frontage = $cgi->param('WATER_FRONTAGE'); $short_description = $cgi->param('SHORT_DESCRIPTION'); $description = $cgi->param('DESCRIPTION'); $comments = $cgi->param('COMMENTS'); $area = $cgi->param('AREA'); $project = $cgi->param('PROJECT'); $zoning = $cgi->param('ZONING'); $taxes = $cgi->param('TAXES'); $tax_year = $cgi->param('TAX_YEAR'); $school_district = $cgi->param('SCHOOL_DISTRICT'); $schools = $cgi->param('SCHOOLS'); $mls = $cgi->param('MLS'); $price = $cgi->param('PRICE'); $downpayment = $cgi->param('DOWNPAYMENT'); $property_type = $cgi->param('PROPERTY_TYPE'); $thumbnail_photo = $cgi->param('THUMBNAIL_PHOTO'); $large_photo = $cgi->param('LARGE_PHOTO'); $tour_photos = $cgi->param('TOUR_PHOTOS'); $virtual_tour = $cgi->param('VIRTUAL_TOUR'); $virtual_tour_url = $cgi->param('VIRTUAL_TOUR_URL'); $flyer_url = $cgi->param('FLYER_URL'); $file1 = $cgi->param('file1'); $file2 = $cgi->param('file2'); $file3 = $cgi->param('file3'); $file4 = $cgi->param('file4'); $file5 = $cgi->param('file5'); $file6 = $cgi->param('file6'); $file7 = $cgi->param('file7'); $file8 = $cgi->param('file8'); $file9 = $cgi->param('file9'); $file10 = $cgi->param('file10');

In reply to Simplifying the following code by Stamp_Guy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.