I strongly recommend going through your code, trying to identify logical "chunks", and pulling them into functions. After you have done that, you will wind up with more maintainable code.

As a side benefit it should then be easy to take the body of your code and turn it into a function that takes an IP address as a parameter. Then you can solve your original problem by calling your function 10 times in a loop.

In case you don't know how to write a function in Perl, you just do it very simply like this:

# declare a function sub my_function_name { # Your input parameters will be in the array @_... my $first_arg = shift(@_); my @remaining args = @_; # Then do whatever you want here... print "Hello, world\n"; # And return data return "Whatever you want to\n"; } # And then you call it like this: my_function_name("First argument", "the", "rest", "of", "them");
For more on functions, try perldoc perlsub.

UPDATE
BTW rather than manually calling sendmail, I would recommend using Mail::Send.


In reply to Re (tilly) 1: Incorporating each while loop and email into one loop? by tilly
in thread Incorporating each while loop and email into one loop? by dru145

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.