I have a code where I want to check wether a number is bigger than or smaller than some limits, $maxdet and $mindet. These two values are given on the command line using the
Getopt::Long module.

However it seems like the code evaluates the if statement as a string (since numbers between 20 and 30 also triggers the loop (when $mindet=200 and $maxdet=300). Any idea what I am
doing wrong???

Cheers
Tommy


[EMAIL PROTECTED]
http://homepage.mac.com/tgrav/

"Any intelligent fool can make things bigger,
more complex, and more violent. It takes a
touch of genius -- and a lot of courage --
to move in the opposite direction"
                         -- Albert Einstein



use strict ;
use warnings ;

use Getopt::Long ;
use Data::Dumper ;
use Pod::Usage ;

use PS::MOPS::DC::SSM ;
use PS::MOPS::DC::Detection ;

my $object ;
my $orb ;
my $orb_i ;
my $in_fname ;
my $orbit_elements ;
my $maxdet = 100000 ;
my $mindet = 0 ;

GetOptions('object=s'=>\$object,
           'maxdet=i'=>\$maxdet,
           'mindet=i'=>\$mindet,
           'infile=s'=>\$in_fname) or pod2usage(2) ;

open INFILE, "< $in_fname" ;
open LOGFILE, ">> output.log" ;

while(<INFILE>) {
my ($tmp1, $tmp2, $tmp3, $tmp4, $tmp5, $tmp6, $tmp7, $tmp8, $name) = split ;

    $orbit_elements = modcs_retrieve(objectName=>$name) ;

    if($name =~ /^$object/) {
        printf(LOGFILE " The object is %s    - ", $name) ;

        my $num_detections = 0 ;
        my $detection ;
        my @detection_id ;
        my $detection_list = modcd_retrieve(objectName=>$name) ;

        while ($detection=$detection_list->next) {
            $num_detections++ ;
            #$num_detections = push @detection_id, $detection ;
        }
printf(LOGFILE "The number of detections : %4d %4d %4d \n", $num_detections, $mindet, $maxdet) ;

if(($num_detections > $mindet) and ($num_detections < $maxdet)) {
            my $out_fname = $name . ".eph" ;
            my $success = open OUTFILE, "> $out_fname" ;
            if(not $success) {
                printf("The file $out_fname could not be opened \n") ;
                next ;
            }
            printf(OUTFILE " %8.5lf   %8.5lf   %9.5lf \n",
                    $orbit_elements->{q},
                    $orbit_elements->{e},
                    $orbit_elements->{i}) ;
            printf(OUTFILE " %7.3lf   %7.3lf   %12.5lf   %12.5lf  \n",
                    $orbit_elements->{node},
                    $orbit_elements->{argPeri},
                    $orbit_elements->{timePeri},
                    $orbit_elements->{epoch}) ;

            $detection_list = modcd_retrieve(objectName=>$name) ;
            while($detection=$detection_list->next) {
                printf(OUTFILE "%12.5lf   %7.3lf   %7.3lf   %7.3lf \n",
                        $detection->{epoch},
                        $detection->{ra},
                        $detection->{dec},
                        $detection->{mag}) ;
            }
            close OUTFILE ;
        }
    }
}

close LOGFILE ;

Reply via email to