$ pt 3.ut.pl $ ./3.ut.pl Make query number 1? [Y] :Y row1 is Moon 4h 57m 4s +19° 5.9' 58.6 ER 51.804 −58.490 Up row2 is Pluto 19h 30m 31s −21° 56.1' 34.700 −27.638 85.830 Set Make query number 2? [Y] :Y row1 is Moon 23h 50m 34s −5° 55.0' 63.0 ER −12.242 93.887 Set row2 is Pluto 19h 33m 27s −21° 51.7' 34.609 −64.053 148.382 Set ... row1 is Moon 19h 32m 42s −21° 14.0' 63.1 ER 22.146 16.263 Up row2 is Pluto 19h 32m 43s −21° 52.8' 34.644 21.516 16.112 Up Make query number 18? [Y] :Y row1 is Moon 19h 32m 43s −21° 14.0' 63.1 ER 22.126 16.363 Up row2 is Pluto 19h 32m 43s −21° 52.8' 34.644 21.495 16.214 Up equal seconds is 2458517.329784 ... $ #### equal, while condition fails at julian second 2458489.99538359 19 Moon 19h 28m 49s −21° 17.9' 63.2 ER −42.931 −103.221 Set 19 Pluto 19h 28m 49s −21° 58.6' 34.696 −43.388 −102.531 Set equal seconds is 2458489.99538359 $ #### $ cat 3.ut.pl #!/usr/bin/perl -w use 5.011; use WWW::Mechanize::GZip; use HTML::TableExtract; use Prompt::Timeout; use open ':std', OUT => ':utf8'; use constant TIMEOUT => 3; use constant MAXTRIES => 30; use Data::Dumper; ### re-set for ultima thule # declarations, initializations to precede main control my ( $ra1_seconds, $ra2_seconds, $equal_sec, $equal ); # set time boundaries my ( $before_bound, $after_bound ) = ( 2458467.0, 2458500); # 2458487.85873 is while I'm adding comments #approximately now, give or take 30 days #oh gosh, I can hardly remember analysis, please forgive # seeking a "conjunction" in the above dense interval # hard code 2 objects to look at (rows) my $e1 = 5; #moon my $e2 = 11; #pluto ## so yeah, a lot of hard-coding here. These values should work my $column = 1; #right ascension my $filename = '3.ut.txt'; #output file my $now_string = localtime; # start logfile open( my $jh, '>>', $filename ) or die "Could not open file '$filename' $!"; say $jh "Script executed at $now_string"; my $attempts = 1; my ( $lower, $upper ) = ( $before_bound, $after_bound ); my $site = 'http://www.fourmilab.ch/yoursky/cities.html'; my $mech = 'WWW::Mechanize::GZip'->new; $mech->get($site); ## need to be specific about where we are looking from # You can find a list on the site for someplace near you $mech->follow_link( text => 'Portland OR' ); $mech->set_fields(qw'date 2'); #julian date specified my $ref_final; #reference to outlive what follows # determine equality by contracting stochastically while ( ( ( $attempts == 1 ) || ( $ra2_seconds != $ra1_seconds ) ) ) { my $default = ( ( $attempts >= MAXTRIES ) ) ? 'N' : 'Y'; my $answer = prompt( "Make query number $attempts?", $default, TIMEOUT ); exit if $answer =~ /^N/i; # guess always a value interior to the time interval # It lands between 40 and 60 percent, flat random # means sims go differently every time my $guess = closetohalf( $upper, $lower ); # feed that guess to the friendly folks at fourmilab # get the ephemeris at that time: $mech->set_fields( jd => $guess ); $mech->click_button( value => "Update" ); my $te = 'HTML::TableExtract'->new; $te->parse( $mech->content ); my $table = ( $te->tables )[3]; #ephemeris table # looking to get the whole rows # array manipulations my $aoa_ref = $table->rows(); $ref_final = $aoa_ref; my $row_ref1 = $table->row($e1); my @row1 = @$row_ref1; say "row1 is @row1"; my $row_ref2 = $table->row($e2); my @row2 = @$row_ref2; say "row2 is @row2"; my $ra1 = $row1[$column]; my $ra2 = $row2[$column]; # create natural numbers from RA $ra1_seconds = string_to_second($ra1); $ra2_seconds = string_to_second($ra2); # the planets win this game when I find a time s.t. # their right ascensions are equal. # I wouldn't guarantee this during retrogade observance if ( $ra2_seconds < $ra1_seconds ) { $upper = $guess; } elsif ( $ra1_seconds < $ra2_seconds ) { $lower = $guess; } else { $equal = $guess; say $jh "equal, while condition fails at julian second $equal"; $equal_sec = $ra1_seconds; } say $jh "$attempts @row1"; say $jh "$attempts @row2"; $attempts++; } say $jh "equal seconds is $equal"; say "equal seconds is $equal"; print Dumper $ref_final; sub string_to_second { my $string = shift; my $return; if ( my $success = $string =~ /^(\d*)h\s+(\d*)m\s+(\d*)s$/ ) { $return = 3600 * $1 + 60 * $2 + $3; } else { } return $return; } # I love this one: sub closetohalf { my ( $up, $low ) = @_; $low + ( $up - $low ) * ( 0.4 + rand 0.2 ); } $