in reply to Shortening long and dirty code

Incorperate the processing of the uploaded file into a subroutine. The subroutine will be passed the result from param('upload' . $n), where $n is the number of the upload field.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Shortening long and dirty code
by sulfericacid (Deacon) on Sep 04, 2003 at 20:19 UTC
    I have very little experience with subroutines in general but I think you're right, that would be the easiest way to go about doing this. Do you mean I should keep my if statements and instead of posting the same code in the iteration instead just call the same subroutine for each of them?

    Thanks!

    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid

      No need to keep the ifs. Do it in a loop:

      foreach my $i (1 .. 4) { call_sub( param("upload$i") ); }

      The code in the subroutine would basically be what is now in your if statements.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      Note: All code is untested, unless otherwise stated