I think your basic question is solved, and ysth has warned you about a possible risk with your open() statements. I have a slightly different admonishment about getting the file names (and min/max params):

Use @ARGV, and get the file names, and min/max values as well, from the command line, instead of forcing the user into a dialog with printed prompts and keyboard input via STDIN. You can look at the Getopt::Long and Getopt::Std modules to see how most people do this sort of thing, or you can easily "roll your own" -- something like this:

my $Usage = "Usage: $0 --min MIN --max MAX --in INFILE --out OUTFILE\n +"; my %args; while ( @ARGV >= 2 ) { if ( $ARGV[0] =~ /^--(min|max|in|out)$/ ) { my $opt = substr( shift, 2 ); $args{$opt} = shift; } else { last; } } die $Usage if ( @ARGV or ( keys %args != 4 )); # all 4 args are mandatory, and only these 4 args are allowed # now use $args{in} instead of $input, etc...
(But really, the Getopt modules are worthwhile -- reading their man pages is time well spent.)

There are several reasons for using command-line args in @ARGV instead of a runtime dialog with the user:

Note that the ordering of arg flags is flexible: "--min 0" can come before or after "--max 10", and likewise for the file name args; all that matters is that each value comes immediately after its flag.


In reply to Re: Making two loops into one by graff
in thread Making two loops into one by srkaeppler

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.