time and place of satellite coincidence

L

Larry Gates

For persons who study our spacial roller derby, it was an eventful week. A
satellite built in the soviet era and an american, the uss colbert,
collided above Siberia. While there are those who may have lost millions
of dollars in the collision, I can't imagine a suit that wouldn't be
laughed out of court, if only because you would necessarily be in the
*other guy's court.* Either Americans sue Putin, *bcyevo horoshova,* or
russinas sue an american satellite company that caused nobody harm.

So it is that I think both space agencies best work together to recover the
data of this orbital orgasm for rocket scientists. Of course, each side
will need two weeks before initial contact at the agency level. This was a
violation of reykjavik, if the american accelerated toward the hurtling
rock. It is also a violation of reykjavik, if the russian satellite got an
IQ boost before impact.

Anyways, this is my version of determining the most time sensitive problem
with these data. Where and when did it occur?


use strict;
use warnings;
use LWP::Simple;

# load the complete content of the url in question
# via LWP::Simple::get(...)

my $site_url = 'http://www.fourmilab.ch/cgi-bin/Yoursky';
my $url_args = 'z=1&lat=65.0&ns=North&lon=90&ew=East';

my $t = 'Something went right!';
print "t is $t\n";

$t = (get "$site_url?$url_args" or "Problem");


print "t is $t\n";


# perl tree4.pl


I believe that the julian time of the coincidence is shown here:
http://i41.tinypic.com/2pqrupy.jpg

I have this as a leftover part from previous inquiries:

foreach my $elem ( $tree->find_by_attribute('name', 'jd') ) {
print $elem->attr('value'), "\n";
}

This will get me the julian time from this point north and west of the
cosmopolitan of yakutsk. How do I instead, give IT the julian time from a
perl script?

I've taken a look at the cpan for TreeuBuilder. A lot of it I don't get.
This is what a synopsis looks like:

foreach my $file_name (@ARGV) {
my $tree = HTML::TreeBuilder->new; # empty tree
$tree->parse_file($file_name);
print "Hey, here's a dump of the parse tree of $file_name:\n";
$tree->dump; # a method we inherit from HTML::Element
print "And here it is, bizarrely rerendered as HTML:\n",
$tree->as_HTML, "\n";

# Now that we're done with it, we must destroy it.
$tree = $tree->delete;
}

<center><h1>Sky above 65N 90E at Sat 2009 Feb 14 4:33 UTC</h1></center>
<center>

How do I grab what lies between the center tags?

--
larry gates

Well, enough clowning around. Perl is, in intent, a cleaned up and
summarized version of that wonderful semi-natural language known as
"Unix".
-- Larry Wall in <[email protected]>
 
T

Tad J McClellan

Larry Gates said:
I have this as a leftover part from previous inquiries:

foreach my $elem ( $tree->find_by_attribute('name', 'jd') ) {
print $elem->attr('value'), "\n";
}

This will get me the julian time from this point north and west of the
cosmopolitan of yakutsk. How do I instead, give IT the julian time from a
perl script?


perldoc -q form

How do I automate an HTML form submission?

<center><h1>Sky above 65N 90E at Sat 2009 Feb 14 4:33 UTC</h1></center>
<center>

How do I grab what lies between the center tags?


------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;

my $site_url = 'http://www.fourmilab.ch/cgi-bin/Yoursky';
my $url_args = 'z=1&lat=35.0836&ns=North&lon=106.651&ew=West';
my $t = get "$site_url?$url_args" || "Problem";

my $tree = HTML::TreeBuilder->new_from_content($t);

foreach my $elem ( $tree->look_down('_tag', 'center') ) {
print $elem->as_text(), "\n";
}
 
L

Larry Gates

perldoc -q form

How do I automate an HTML form submission?

How do I automate an HTML form submission?
If you are doing something complex, such as moving through many pages
and forms or a web site, you can use "WWW::Mechanize". See its
documentation for all the details.

If you're submitting values using the GET method, create a URL and
encode the form using the "query_form" method:

use LWP::Simple;
use URI::URL;

my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
$content = get($url);

If you're using the POST method, create your own user agent and encode
the content appropriately.

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

$ua = LWP::UserAgent->new();
my $req = POST 'http://www.perl.com/cgi-bin/cpan_mod',
[ module => 'DB_File', readme => 1 ];
$content = $ua->request($req)->as_string;


I think I can get my head around this.
------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;

my $site_url = 'http://www.fourmilab.ch/cgi-bin/Yoursky';
my $url_args = 'z=1&lat=35.0836&ns=North&lon=106.651&ew=West';
my $t = get "$site_url?$url_args" || "Problem";

my $tree = HTML::TreeBuilder->new_from_content($t);

foreach my $elem ( $tree->look_down('_tag', 'center') ) {
print $elem->as_text(), "\n";
}
------------------------------


4:30 local. cputz hago.
 
L

Larry Gates

#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;

my $site_url = 'http://www.fourmilab.ch/cgi-bin/Yoursky';
my $url_args = 'z=1&lat=35.0836&ns=North&lon=106.651&ew=West';
my $t = get "$site_url?$url_args" || "Problem";

my $tree = HTML::TreeBuilder->new_from_content($t);

foreach my $elem ( $tree->look_down('_tag', 'center') ) {
print $elem->as_text(), "\n";

I try to balance my posts between things that have worked and things that
haven't, and I think I'm at the tipping point now.

I get output I like for part of it, but I can't extend the methods to reach
a solution. This version was working until I tried to incorporate stuff
from HTML::Element, and then I get the complaints from perl.exe:

#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;



my $site_url = 'http://www.fourmilab.ch/cgi-bin/Yoursky';
my $url_args = 'z=1&lat=35.0836&ns=North&lon=106.651&ew=West';
my $t = get "$site_url?$url_args" || "Problem";

my $tree = HTML::TreeBuilder->new_from_content($t);

foreach my $elem ( $tree->look_down('_tag', 'center') ) {

print "%%\n", $elem;
print $elem->as_text(), "\n";
}

foreach my $elem ( $tree->find_by_attribute('name', 'jd') ) {
print "****";
print $elem->attr('value'), "\n";
}

use HTML::Element;
$a = HTML::Element->new('a', href => 'http://www.perl.com/');
$a->push_content("The Perl Homepage");

$tag = $a->tag;
print "$tag starts out as:", $a->starttag, "\n";
print "$tag ends as:", $a->endtag, "\n";
print "$tag\'s href attribute is: ", $a->attr('href'), "\n";

$links_r = $a->extract_links();
print "Hey, I found ", scalar(@$links_r), " links.\n";

print "And that, as HTML, is: ", $a->as_HTML, "\n";
$a = $a->delete;



# perl index6.pl

#end script; show dump of dos windwo

C:\MinGW\source>perl index6.pl
%%
HTML::Element=HASH(0x1acf1d0)Sky above 35â–‘5'N 106â–‘39'3"W at Mon 2009 Feb 16
4:32
UTC
%%
HTML::Element=HASH(0x1af74f4)Explain symbols in the map.Click in map to aim
tele
scope.View horizon at this observing site.
%%
HTML::Element=HASH(0x1af78b4)Explain controls in the following panel.Date
and Ti
me Now Universal time: Julian day:Observing Site Latitude: North South
Longitud
e: East WestSet for nearby cityDisplay Options Ecliptic and equator Moon
and pl
anets Deep sky objects of magnitude and brighter Constellations: áááááááá
Outli
nes áááááááá Names aligned with horizon? áááááááá BoundariesStars:
ááááááááShow
stars brighter than magnitude áááááááá Names for magnitude and brighter
ááááá
ááá Bayer/Flamsteed codes for mag. and brighter Invert North and
SouthImage si
ze: pixels Colour scheme: ColourBlack on white backgroundWhite on black
backgro
undNight vision (red)Asteroid andComet Tracking Paste orbital elements
below: E
cho elements

%%
Wide character in print at index6.pl line 18.
HTML::Element=HASH(0x1b08cd0) RightAscensionDeclinationDistance(AU)From
35┬░5'N
106°39'3"W:AltitudeAzimuthSun21h 59m 16s−12°
17.8'0.988−45.719110.332SetM
ercury20h 15m 33s−19° 47.0'1.017−69.097132.831SetVenus0h 28m 22s+7°
18.9'0
..451−4.407102.133SetMoon15h 2m 48s−22° 37.9'62.5
ER−35.118−85.358SetMar
s20h 46m 38s−19° 1.2'2.309−63.450120.976SetJupiter20h 49m 21s−18°
16.0'6
..029−62.468121.250SetSaturn11h 26m 37s+6°
1.6'8.46024.724−79.502UpUranus23h
28m 52s−4° 9.4'21.000−23.167101.784SetNeptune21h 46m 2s−13°
50.1'31.019
−49.201111.502SetPluto18h 10m 47s−17°
43.5'32.153−68.083−138.502Set
****2454878.68916

C:\MinGW\source> perl index6.pl
Global symbol "$tag" requires explicit package name at index6.pl line 30.
Global symbol "$tag" requires explicit package name at index6.pl line 31.
Global symbol "$tag" requires explicit package name at index6.pl line 32.
Global symbol "$tag" requires explicit package name at index6.pl line 33.
Global symbol "$links_r" requires explicit package name at index6.pl line
35.
Global symbol "$links_r" requires explicit package name at index6.pl line
36.
Execution of index6.pl aborted due to compilation errors.

C:\MinGW\source>

Outside of basically not knowing my I failed here, I have 2 other
questions.

q1) I didn't see look_down as a method in HTML::TreeBuilder, HTML::Element
and one other HTML::Something that I looked for it. Where do I find a
definition of the look_down method?

q2) I *still* have problems with control structures in perl. Why does
this not print the index variable for the loop?

#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;

my $site_url = 'http://www.fourmilab.ch/cgi-bin/Yoursky';
my $url_args = 'z=1&lat=35.0836&ns=North&lon=106.651&ew=West';
my $t = get "$site_url?$url_args" || "Problem";

my $tree = HTML::TreeBuilder->new_from_content($t);

foreach my $elem ( $tree->look_down('_tag', 'center') ) {

print "%%\n", $elem;
print $elem->as_text(), "\n";
}

# perl index3.pl

Thanks for your comment.
 
P

Peter J. Holzer

C:\MinGW\source> perl index6.pl
Global symbol "$tag" requires explicit package name at index6.pl line 30.
Global symbol "$tag" requires explicit package name at index6.pl line 31.
Global symbol "$tag" requires explicit package name at index6.pl line 32.
Global symbol "$tag" requires explicit package name at index6.pl line 33.
Global symbol "$links_r" requires explicit package name at index6.pl line
35.
Global symbol "$links_r" requires explicit package name at index6.pl line
36.
Execution of index6.pl aborted due to compilation errors.

C:\MinGW\source>

Outside of basically not knowing my I failed here,

You forgot to declare the variables "$tag" and "$links_r".
I have 2 other
questions.

q1) I didn't see look_down as a method in HTML::TreeBuilder, HTML::Element

Strange. I see it in HTML::Element (in section "Secondary Structural
Methods", near line 800 when formatted for 80 chars/line).
and one other HTML::Something that I looked for it. Where do I find a
definition of the look_down method?

It doesn't seem to be the problem here, but in general:

One of the primary techniques in object-oriented programming is
inheritance. If class X is a subclass of class Y and class Y is a
subclass of class Z, then X inherits all methods from Y and Z. Typically
these methods are documented only once (in Y or Z - wherever they are
defined), so for a complete documentation of X, you need to read all
three perldocs. The documentation of X should mention that X is a
subclass of Y and the documentation of Y should mention that Y is a
subclass of Z, but sometimes that hint is missing or well hidden.

q2) I *still* have problems with control structures in perl. Why does
this not print the index variable for the loop?
[...]
foreach my $elem ( $tree->look_down('_tag', 'center') ) {

print "%%\n", $elem;
print $elem->as_text(), "\n";
}

There is no "index variable" in this example. There is the "loop variable"
$elem, but it isn't an index in any sense of the word.

If you mean $elem, that is printed just fine. Why do you think it isn't?

Or in other words:

* What did you expect the output to be?
* What was the real output?

hp
 
T

Tad J McClellan

use strict;


Here you have made a promise that you will declare all variables
before you use them.

If you break your promise, perl will refuse to run your program.


[ snip 15 lines of code ]

use HTML::Element;


"use" is a compile-time statement, so this executes *before*
the 15 (run-time) lines that come before it.

It will work here, but it can be confusing to have lines that
are evaluated early appear late in the code...

$tag = $a->tag;
$links_r = $a->extract_links();


You have broken your promise by not declaring these 2 variables.

Outside of basically not knowing my I failed here, I have 2 other
^^
^^ a fortuitous freudian slip here
questions.


Put "my " before $tags and $links_r so as to keep your promise.

q1) I didn't see look_down as a method in HTML::TreeBuilder, HTML::Element
and one other HTML::Something that I looked for it. Where do I find a
definition of the look_down method?


I dunno what's going on here.

I see it in the docs for HTML::Element just fine.

q2) I *still* have problems with control structures in perl. Why does
this not print the index variable for the loop? ^^^^^^^^^^^^^^

foreach my $elem ( $tree->look_down('_tag', 'center') ) {

print "%%\n", $elem;
print $elem->as_text(), "\n";
}

perldoc perlsyn

Foreach Loops

The C<foreach> loop iterates over a normal list value and sets the
variable VAR to be each element of the list in turn.

$elem is "each element of the list",
not "the index of each element in the list"

With foreach, the programmer does not need to (or have access to) know
any indexes, perl does the indexing for you automatically and simply
returns the indexed *values*.

So, $elem is an HTML::Element object. Your loop is printing the
stringified object (HTML::Element=HASH...) just fine.
 
L

Larry Gates

You forgot to declare the variables "$tag" and "$links_r".

I should recognize errors like that by now.:-(
Strange. I see it in HTML::Element (in section "Secondary Structural
Methods", near line 800 when formatted for 80 chars/line).

Thanks for your response, Peter. Programming in perl is very exacting as
far as one's attention to detail goes. I wasn't sure if HTML::Element was
where I should be looking. I dumped it as a tree today, and it's a fairly
large html page.
and one other HTML::Something that I looked for it. Where do I find a
definition of the look_down method?

It doesn't seem to be the problem here, but in general:

One of the primary techniques in object-oriented programming is
inheritance. If class X is a subclass of class Y and class Y is a
subclass of class Z, then X inherits all methods from Y and Z. Typically
these methods are documented only once (in Y or Z - wherever they are
defined), so for a complete documentation of X, you need to read all
three perldocs. The documentation of X should mention that X is a
subclass of Y and the documentation of Y should mention that Y is a
subclass of Z, but sometimes that hint is missing or well hidden.
ok
q2) I *still* have problems with control structures in perl. Why does
this not print the index variable for the loop?
[...]
foreach my $elem ( $tree->look_down('_tag', 'center') ) {

print "%%\n", $elem;
print $elem->as_text(), "\n";
}

There is no "index variable" in this example. There is the "loop variable"
$elem, but it isn't an index in any sense of the word.

If you mean $elem, that is printed just fine. Why do you think it isn't?

Or in other words:

* What did you expect the output to be?

I don't know.

#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;
use HTML::Element;


my $site_url = 'http://search.cpan.org/';
my $url_args = '~petek/HTML-Tree-3.23/lib/HTML/TreeBuilder.pm';
my $t = get "$site_url?$url_args" || "Problem";

my $tree1 = HTML::TreeBuilder->new_from_content($t);

print "this is one of the answer's to today's questions\n";
print $tree1, "\n";


#$tree1->dump;

$site_url = 'http://www.fourmilab.ch/cgi-bin/Yoursky';
$url_args = 'z=1&lat=35.0836&ns=North&lon=106.651&ew=West';
my $r = get "$site_url?$url_args" || "Problem";

my $tree2 = HTML::TreeBuilder->new_from_content($r);

# $tree2->dump;

my $i=0;

foreach my $elem ( $tree2->look_down('_tag', 'center') ) {
++ $i;
print "i is $i\n";
print "elem is $elem\n";

print $elem->as_text(), "\n";
}

foreach my $elem ( $tree2->find_by_attribute('name', 'lat') ) {
print "****";
print $elem->attr('value'), "\n";
}

# perl index12.pl >text42.txt

#end script begin output

C:\MinGW\source> perl index12.pl
this is one of the answer's to today's questions
HTML::TreeBuilder=HASH(0x1ada044)
i is 1
elem is HTML::Element=HASH(0x1af0660)
Sky above 35â–‘5'N 106â–‘39'3"W at Tue 2009 Feb 17 4:46 UTC
i is 2
elem is HTML::Element=HASH(0x1b0add8)
Explain symbols in the map.Click in map to aim telescope.View horizon at
this ob
serving site.
i is 3
elem is HTML::Element=HASH(0x1b0b18c)
Explain controls in the following panel.Date and Time Now Universal time:
Julian
day:Observing Site Latitude: North South Longitude: East WestSet for
nearby c
ityDisplay Options Ecliptic and equator Moon and planets Deep sky objects
of mag
nitude and brighter Constellations: áááááááá Outlines áááááááá Names
aligned wi
th horizon? áááááááá BoundariesStars: ááááááááShow stars brighter than
magnitude
áááááááá Names for magnitude and brighter áááááááá Bayer/Flamsteed
codes for
mag. and brighter Invert North and SouthImage size: pixels Colour
scheme: Co
lourBlack on white backgroundWhite on black backgroundNight vision
(red)Asteroid
andComet Tracking Paste orbital elements below: Echo elements

i is 4
elem is HTML::Element=HASH(0x1b1add4)
Wide character in print at index12.pl line 36.
 RightAscensionDeclinationDistance(AU)From 35°5'N
106┬░39'3"W:AltitudeAzimuthS
un22h 3m 11s−11° 56.7'0.988−48.097113.831SetMercury20h 20m 24s−19°
40.9'
1.033−70.822140.046SetVenus0h 30m 17s+7°
42.0'0.444−7.305104.781SetMoon15h
55m 3s−25° 18.3'63.0 ER−43.384−86.854SetMars20h 49m 51s−18°
48.9'2.307
−65.757126.860SetJupiter20h 50m 18s−18°
12.4'6.024−65.240127.682SetSaturn
11h 26m 21s+6° 3.4'8.45328.323−76.580UpUranus23h 29m 4s−4°
8.1'21.007−26
..625104.688SetNeptune21h 46m 11s−13°
49.3'31.018−52.469115.792SetPluto18h 1
0m 53s−17° 43.5'32.139−65.513−130.135Set
****35â–‘5'

C:\MinGW\source>
* What was the real output?

hp


It's a hash?
 
L

Larry Gates

How do I automate an HTML form submission?
If you are doing something complex, such as moving through many pages
and forms or a web site, you can use "WWW::Mechanize". See its
documentation for all the details.

If you're submitting values using the GET method, create a URL and
encode the form using the "query_form" method:

use LWP::Simple;
use URI::URL;

my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
$content = get($url);

#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;
use HTML::Element;
use URI::URL;

my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
my $content = get($url);
print $url;
# perl Uri1.pl

C:\MinGW\source> perl Uri1.pl
Global symbol "$content" requires explicit package name at Uri1.pl line 16.
Execution of Uri1.pl aborted due to compilation errors.

** I included this one to show that I caught my lack of a my here. ^^

C:\MinGW\source> perl Uri1.pl
http://www.perl.com/cgi-bin/cpan_mod?module=DB_File&readme=1
C:\MinGW\source>

It looks to me like we are simulating pressing buttons and adding values;
is that correct?
--
larry gates

Personally I'm looking forward to seeing what the .mathematica method
spits out for a junction, but maybe I'll have to settle for a .apl
method instead.
-- Larry Wall in <[email protected]>
 
L

Larry Gates

#!/usr/bin/perl
use warnings;
use strict;
use HTML::TreeBuilder;
use LWP::Simple;
use HTML::Element;
use URI::URL;

my $url = url('http://www.perl.com/cgi-bin/cpan_mod');
$url->query_form(module => 'DB_File', readme => 1);
my $content = get($url);
print $url;
# perl Uri1.pl

I'm still scratching my head on this one. This is what it looks like when
you fire up the link in a brwoser:

http://i41.tinypic.com/rk4f40.jpg
--
larry gates

It's, uh, pseudo code. Yeah, that's the ticket...
[...]
And "unicode" is pseudo code for $encoding. :)
-- Larry Wall in <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top