Tommy Grav wrote:
> 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???
You might have that problem if you were using the 'gt' and 'lt' operators
however your code is using the '>' and '<' operators which give the correct
behaviour.
> 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" ;
You should *ALWAYS* verify that the files were opened correctly.
open INFILE, "< $in_fname" or die "Cannot open '$in_fname' $!";
open LOGFILE, ">> output.log" or die "Cannot open 'output.log' $!";
> while(<INFILE>) {
> my ($tmp1, $tmp2, $tmp3, $tmp4, $tmp5, $tmp6, $tmp7, $tmp8, $name)
> = split ;
You are needlessly creating eight variables:
my (undef, undef, undef, undef, undef, undef, undef, undef, $name) = split;
Or using a list slice:
my $name = ( split )[ 8 ];
> $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") ;
You shouldn't use interpoled variables in printf format strings, either:
printf "The file %s could not be opened \n", $out_fname;
Or:
print "The file $out_fname could not be opened \n";
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>