Hi there,

Here's a possible solution for you - I've listed two versions.
orient_full() is the original version I wrote, and then I tidied it up
and removed the if statements to make the second version called
orient()

Is this what you were looking for?

Thanks,

Matt

#!/usr/bin/perl
use strict;
use warnings;
use PDL;


print orient_full(230, 320, 5);
print orient_full(230, 321, 5);
print orient_full(340, 15 , 5);
print orient_full(340, 16 , 5);

print orient(230, 320, 5);
print orient(230, 321, 5);
print orient(340, 15 , 5);
print orient(340, 16 , 5);

sub orient {

    use strict;
    my ($a, $b, $step) = @_;

    my $newb = $b;

    if ($a > $b) { $newb = $b + 360.; } # dogs and cats, living
together, mass hysteria

    my $nstep = ($newb - $a) / $step;

    # nstep will quietly round down to an integer
    my $ret = $a + $step * sequence($nstep);

    return ($ret % 360.);

}

sub orient_full {

    use strict;
    my ($a, $b, $step) = @_;

    if ($a < $b) {
        my $nstep = ($b - $a) / $step;

        # nstep will quietly round down to an integer
        my $ret = $a + $step * sequence($nstep);

        return($ret);
        exit;
    }

    if ($a > $b) {  # dogs and cats, living together, mass hysteria

        my $newb = $b + 360.; # now b is much bigger than a
        my $nstep = ($newb - $a) / $step;

        my $ret = $a + $step * sequence($nstep);
        return ($ret % 360.);

    }

}



-- 
Matthew Kenworthy / Assistant Professor / Leiden Observatory
Niels Bohrweg 2 (#463) / P.O. Box 9513 / 2300 RA Leiden / NL

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to