Without getting into testing, it look very much as if you could simply move the body of the second while loop into the body of the if statement in the first; skip the holder file stuff and rename @firstline* to @mag to match the usage in the first loop.

* Bad name. It's an array not a line and it it used by every line, not just the first??

Untested (no data), but something along these lines should do it.

#!/usr/bin/perl -w print "What is input file name?: "; chomp($input = <STDIN>); print "What is output file name: "; chomp($output = <STDIN>); print "What is the mininum magnitude?:"; chomp($min_mag = <STDIN>); print "What is maximum magnitude?:"; chomp($max_mag = <STDIN>); #opening up ngc188cata and putting it into INPUT# open (INPUT, "$input") || die "died opening input\n"; #opening up ngc188cat2 and setting output of out# open (STDOUT, ">$output") || die "died opening output\n"; $cfo = "O"; $status = "STATUS=OK"; while ($inline = <INPUT>) { #INPUT defined as variable# #firstline of array defined by split of white space into variable +inline @mag = split(/\s+/, $inline); if ($mag[12] >= $min_mag && $mag[12] <= $max_mag) { $hms1 = $mag[2]; $rah2 = ($hms1 / 15); $rah3 = int($rah2); $ram1 = ( abs($rah2 - $rah3) )* 60; $ram2 = int($ram1); $ras1 = abs($ram1 - $ram2) * 60; $ras2 = sprintf "%-02.3f", $ras1; $hms2 = $mag[3]; $hh2 = sprintf "%1d", ($hms2); $mm2 = sprintf "%02d", (60*( abs($hms2) - abs($hh2) ) ); $ss2 = sprintf "%-02.2f", 3600*abs($hms2) - 3600*abs($hh2) - 60*abs($mm2); $obid = "NGC 188 - $mag[1]"; write; #writing to STDOUT } } close INPUT; close NEW; format STDOUT = @>>> @<<<<<<<<<<<<<<<<<<< @> @> @>>>>> @< @< @>>>> @ @<<<<<<<< $mag[1], $obid, $rah3, $ram2, $ras2, $hh2, $mm2, $ss2, $cfo, $status, .

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re: Making two loops into one by BrowserUk
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.