srkaeppler has asked for the wisdom of the Perl Monks concerning the following question:
Just to explain how i thought about this. The information is ran through the first loop, containing the "if" statement, which takes out the information I want. From there, that information is put into a seperate external file. That external file is then opened and ran through a second loop, which gives me the information i need, that is subsquently formatted into a data report.#!/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>); open (INPUT, "$input") || die "died opening input\n";#opening up ngc18 +8cata and putting it into INPUT# open (STDOUT, ">$output") || die "died opening output\n"; #opening up +ngc188cat2 and setting output of out# $cfo = "O"; $status = "STATUS=OK"; open OUT, "+<holder"; while ($inline = <INPUT>) { #INPUT defined as variable# @mag = split(/\s+/, $inline); #firstline of array defined by split of + white space into variable inline# if ($mag[12] >= $min_mag && $mag[12] <= $max_mag) { print OUT "$inline"; #printing to OUT } } close OUT; open NEW, "+<holder"; while ($sep = <NEW>) { @firstline = split(/\s+/, $sep); $hms1 = $firstline[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 = $firstline[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 - $firstline[1]"; ########################################################### write; #writing to STDOUT } close INPUT; close NEW; format STDOUT = @>>> @<<<<<<<<<<<<<<<<<<< @> @> @>>>>> @< @< @>>>> @ @<<<<<<<< $firstline[1], $obid, $rah3, $ram2, $ras2, $hh2, $mm2, $ss2, $cfo, $st +atus, .
So what i am wondering is how i can clean up the loops, or if it is possible and easy combine the two loops that I have in order to make just one loop? I would perfer to not have an external file ("holder") if at all possible. I would appericate some help, because I am going to have to make some more if loops like this, asking to examine different elements in the original dataset instead.
Thank you!
srkaeppler
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Making two loops into one
by BrowserUk (Patriarch) on Sep 21, 2004 at 21:23 UTC | |
|
Re: Making two loops into one
by graff (Chancellor) on Sep 22, 2004 at 04:20 UTC | |
|
Re: Making two loops into one
by ysth (Canon) on Sep 21, 2004 at 23:17 UTC | |
|
Re: Making two loops into one
by Roy Johnson (Monsignor) on Sep 21, 2004 at 21:22 UTC |