perl_n00b has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use the Astro::MoonPhase module to tell me the % moon illuminated at certain times but it will not return the correct result. All I have is
use Astro::MoonPhase; ($MoonIllum) = phase(); print "$MoonIllum\n";
leaving phase() empty just takes the current time in Unix time. Note that when I enter in a unix time it doesn't work either.

So for today it should return something around .45 but it returns approx .76.

I can't figure out why this won't work. I can correct for GMT time which I assume it uses but that obviously doesn't change the answer much.

Anyone have any ideas?

Replies are listed 'Best First'.
Re: Astro::MoonPhase Issue
by gmargo (Hermit) on Nov 10, 2009 at 03:07 UTC
    #!/usr/bin/perl -w use strict; use warnings; use Astro::MoonPhase; my ( $MoonPhase, $MoonIllum, $MoonAge, $MoonDist, $MoonAng, $SunDist, +$SunAng ) = phase(); print "MoonPhase = $MoonPhase\n"; print "MoonIllum = $MoonIllum\n"; print "MoonAge = $MoonAge\n"; print "MoonDist = $MoonDist\n"; print "MoonAng = $MoonAng\n"; print "SunDist = $SunDist\n"; print "SunAng = $SunAng\n";
    MoonPhase = 0.766679233270294 MoonIllum = 0.44769650565041 MoonAge = 22.6404890872028 MoonDist = 364406.875767821 MoonAng = 0.546526894368734 SunDist = 148126949.396541 SunAng = 0.538424300459282

    The moon's age is only 22.6, younger than me. Who knew?

Re: Astro::MoonPhase Issue
by jethro (Monsignor) on Nov 10, 2009 at 02:54 UTC
    ($MoonPhase,$MoonIllum) = Astro::MoonPhase::phase(); print "$MoonIllum\n"; # prints 0.44839600941596
      Also, does this program actually use GMT? or is that a false assumption on my part?

        The code uses the epoch time (aka GMT or UTC) by default. The documentation states that the calculated values are those for an observer at the center of the earth, which would constitute a point source. There is no correction for the size of the earth or where you happen to be on it.

Re: Astro::MoonPhase Issue
by perl_n00b (Acolyte) on Nov 10, 2009 at 03:03 UTC
    That works! Why did what I have not work?

      Because perl returns results positionally, not by name

      The method phase() returns a lot of results, the first being the Moon Phase, the second the Illumination. You stored the first return parameter, which holds the Moon Phase, into the variable $MoonIllum