inputting the ephemerides

S

sln

You have not answered the question.

Why do you think you need those lines in your program?




Delete those lines and compare the output to when those lines
are included.

There will be no differences.

ie. those lines do not do anything useful, so remove them.

Rofl ........

sln
 
S

sln

You are truly an attention troll.

sln

Please **** your dutch self.

[comp.lang.perl.misc]
!delete From {sln}

Americans, your all the same.
Am Bushed once, er, remember that, er,
am Bushed twice, er, forget me not...

Americans are the 'decider', makes me puke..

sln
 
J

Jürgen Exner

Larry Gates said:
I've been doing this in bite-sixed chunks. The problems that dogged me for
a long time were what to do with tabs, the ER that followed the moon's
distance from earth and no other body's, and the degree sign, which is B0
hex and therefore not ascii.

I don't know what noop is, but I suspect it's a loop that does a whole lot

Short for "No Operation", a commonly used placeholder in assembler
languages..
of nothing.
Right.

I *do* use the $line, because that's what I split on:

No, you don't. The one line that you conveniently snipped is
while (my $line = <$gh>) {

where you declare and define a new $line, which has nothing to do with
the $line from the code segment above, and you re-read the whole,
unaltered file again line by line and
my @s = split / /, $line;

uses those newly read $line.
my @s = split /\s+/, $line;

Do you want to split on space or on white space? You rmight want to make
up your mind.

use strict;
use warnings;
my $filename = 'eph6.txt';
my $filename2 = 'outfile1.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
open(my $gh, $filename2) or die "cannot open $filename2: $!";

while (my $line = <$fh>) {
$line =~ s/\t/ /g;
$line =~ s/ER/ /g;
$line =~ s/°/ /g;
}

You are still reading the while file, modifying all read strings, and
happily throwing them away.
close($fh);

seek($gh,0,0);

At this point $gh has been opened, but never been read from or written
to. Therefore this seek is a NOOP, too.

jue
 
J

Jürgen Exner

Larry Gates said:
seek($gh,0,0);

Here you are seek()ing $gh (for no good reason, I might add).
while (my $line = <$gh>) {

Here you are reading from $gh.
print $hh "$line\n";

Here you are printing to $hh.
I thought I was
reading and writing from $gh but apparently not.

There is no place in all of your code where you are writing to $gh.
I wonder how I ever got
output at all.??

Because print() by default prints to STDOUT if no other filehandle is
specified.

jue
 
S

sln

Short for "No Operation", a commonly used placeholder in assembler
languages..
Noopy, aka 00, the black hole, an instruction your cpu does every cycle
when not active, otherwise known as idle. I don't think that relates to Perl
does it ? Such bullshit !!

sln
 
U

Uri Guttman

LG> my $filename = 'eph6.txt';
LG> my $filename2 = 'outfile1.txt';
LG> open(my $fh, '<', $filename) or die "cannot open $filename: $!";
LG> open(my $gh, $filename2) or die "cannot open $filename2: $!";

LG> while (my $line = <$fh>) {
LG> $line =~ s/\t/ /g;
LG> $line =~ s/ER/ /g;
LG> $line =~ s/°/ /g;
LG> }
LG> close($fh);

i said this before. WHY ARE YOU WRITING out the changed data and then
reading it back in again? just use the lines you cleaned up as you get
them.

LG> seek($gh,0,0);

no need for the seek, the extra file opens, the extra readlines, etc. a
total waste of resources.

LG> while (my $line = <$gh>) {

and you keep not getting how perl is different from c and fortran. i
learned perl from the first camel (the pink one) having used c for many
years. it wasn't so hard to learn if you have been programming as long
as you seem to claim.

uri
 
L

Larry Gates

Here you are seek()ing $gh (for no good reason, I might add).


Here you are reading from $gh.


Here you are printing to $hh.


There is no place in all of your code where you are writing to $gh.


Because print() by default prints to STDOUT if no other filehandle is
specified.

jue

I went back and tried to use STDOUT as my temp file but couldn't get it
together. This purports again to be a solution:

use strict;
use warnings;

my $filename = 'eph6.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
my $filename2 = 'temp6.txt';
open(my $gh, '+>', $filename2) or die "cannot open $filename2: $!";

while (my $line = <$fh>) {
$line =~ s/\t/ /g;
$line =~ s/ER/ /g;
$line =~ s/°/ /g;
print STDOUT $line;
print $gh $line;
}
close($fh);
close($gh);

open(my $hh, '<', $filename2) or die "cannot open $filename2: $!";
my $outfile = 'outfile7.txt';
open(my $ih, '>', $outfile) or die "cannot open $outfile: $!";
while (my $line = <$hh>) {
my @s = split /\s+/, $line;

$s[1] =~ s/h//;
$s[2] =~ s/m//;
$s[3] =~ s/s//;
$s[5] =~ s/'//;
for my $i (0..9) {
print STDOUT "s$i is $s[$i]\n";
}
print "@s\n";
print $ih "@s\n";
}
close($hh);
close($ih);

# perl reg12.pl

C:\MinGW\source>type outfile7.txt
Sun 19 43 51 -21 17.8 0.984 -35.020 87.148 Set
Mercury 20 36 41 -16 59.3 0.747 -22.075 84.236 Set
Venus 22 51 18 -7 46.9 0.691 10.142 72.919 Up
Moon 10 24 21 +7 29.5 58.6 -4.992 -102.785 Set
Mars 18 58 51 -23 33.8 2.398 -45.280 90.860 Set
Jupiter 20 17 22 -20 8.1 6.082 -27.618 83.843 Set
Saturn 11 32 29 +5 16.0 8.806 -19.672 -111.729 Set
Uranus 23 23 12 -4 46.5 20.638 18.211 70.235 Up
Neptune 21 41 17 -14 13.9 30.892 -7.527 77.864 Set
Pluto 18 6 40 -17 44.9 32.485 -52.833 108.052 Set

C:\MinGW\source>


--
larry gates

Maybe we should take a clue from FTP and put in an option like "print
hash marks on every 1024 iterations". :)
-- Larry Wall in <[email protected]>
 
J

Jim Gibson

OK. Here is a quick version of your program with most of the logic
errors removed. Since I did test it, there still may be bugs, but it
should give you the overall logic flow:

use strict;
use warnings;

# open input file
my $filename = 'eph6.txt';
open(my $fh, '<', $filename) or
die "cannot open $filename for reading: $!";

# open output file
my $filename2 = 'outfile1.txt';
open(my $gh, '>', $filename2) or
die "cannot open $filename2 for writing: $!";

# process all lines in input file
while( my $line = <$fh> ) {
chomp($line);
my @s = split /\s+/, $line;

# modify fields
$s[1] =~ s/h//;
$s[2] =~ s/m//;
$s[3] =~ s/s//;
$s[5] =~ s/'//;

# print modified fields
for my $i (0..$#s) {
print "s[$i] = $s[$i]\n";
}

# write modified fields to output file
my $outline = join(' ', @s);
print $gh "$outline\n";
}

# close input and output files
close($gh) or die("Error closing $filename2: $!");
close($fh) or die("Error closing $filename: $!");

__END__

Note that aside from your explicit field modifications, this program
will compress two or more spaces in your input file to one space. If
this is a problem, then you should consider using unpack on the input
data and pack for the output data.

Hope this helps.
 
S

sln

Here you are seek()ing $gh (for no good reason, I might add).


Here you are reading from $gh.


Here you are printing to $hh.


There is no place in all of your code where you are writing to $gh.


Because print() by default prints to STDOUT if no other filehandle is
specified.

jue

I went back and tried to use STDOUT as my temp file but couldn't get it
together. This purports again to be a solution:

use strict;
use warnings;

my $filename = 'eph6.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
my $filename2 = 'temp6.txt';
open(my $gh, '+>', $filename2) or die "cannot open $filename2: $!";

while (my $line = <$fh>) {
$line =~ s/\t/ /g;
$line =~ s/ER/ /g;
$line =~ s/°/ /g;
print STDOUT $line;
print $gh $line;
}
close($fh);
close($gh);

open(my $hh, '<', $filename2) or die "cannot open $filename2: $!";
my $outfile = 'outfile7.txt';
open(my $ih, '>', $outfile) or die "cannot open $outfile: $!";
while (my $line = <$hh>) {
my @s = split /\s+/, $line;

$s[1] =~ s/h//;
$s[2] =~ s/m//;
$s[3] =~ s/s//;
$s[5] =~ s/'//;
for my $i (0..9) {
print STDOUT "s$i is $s[$i]\n";
}
print "@s\n";
print $ih "@s\n";
}
close($hh);
close($ih);

# perl reg12.pl

C:\MinGW\source>type outfile7.txt
Sun 19 43 51 -21 17.8 0.984 -35.020 87.148 Set
Mercury 20 36 41 -16 59.3 0.747 -22.075 84.236 Set
Venus 22 51 18 -7 46.9 0.691 10.142 72.919 Up
Moon 10 24 21 +7 29.5 58.6 -4.992 -102.785 Set
Mars 18 58 51 -23 33.8 2.398 -45.280 90.860 Set
Jupiter 20 17 22 -20 8.1 6.082 -27.618 83.843 Set
Saturn 11 32 29 +5 16.0 8.806 -19.672 -111.729 Set
Uranus 23 23 12 -4 46.5 20.638 18.211 70.235 Up
Neptune 21 41 17 -14 13.9 30.892 -7.527 77.864 Set
Pluto 18 6 40 -17 44.9 32.485 -52.833 108.052 Set

C:\MinGW\source>

Jeez, give it a rest attention hound.

sln
 
J

Jürgen Exner

Uri Guttman said:
LG> my $filename = 'eph6.txt';
LG> my $filename2 = 'outfile1.txt';
LG> open(my $fh, '<', $filename) or die "cannot open $filename: $!";
LG> open(my $gh, $filename2) or die "cannot open $filename2: $!";

LG> while (my $line = <$fh>) {
LG> $line =~ s/\t/ /g;
LG> $line =~ s/ER/ /g;
LG> $line =~ s/°/ /g;
LG> }
LG> close($fh);

i said this before. WHY ARE YOU WRITING out the changed data and then
reading it back in again?

If at least he would write them out. But he is reading them, modifying
the read text, and then discarding the modified text by overwriting it
with the next line from the file.

jue
 
J

Jürgen Exner

Larry Gates said:
I went back and tried to use STDOUT as my temp file but couldn't get it
together. This purports again to be a solution:

AAAAARRRRRRRGGGGGGGG!!!!! HHHHHHEEEEEELLLLPPPPP!!!

Who on earth said anything about using STDOUT as a temp file? You asked
why you got output and I answered that specific question by telling you
that print() defaults to STDOUT if no other filehandle is specified (and
implied that STDOUT is opened automatically at the start of any
program).

What the devil moved you to turn STDOUT into a temp file? Nobody ever
suggested something so stupid! Do you know what STDOUT is? You are
claiming to be familiar with C. I cannot believe that, considering that
stdout is a concept coming from C.

jue
 
L

Larry Gates

You have not answered the question.

Why do you think you need those lines in your program?




Delete those lines and compare the output to when those lines
are included.

There will be no differences.

ie. those lines do not do anything useful, so remove them.

Well, I'll be dipped in shit. You're right. I can understand the
non-necessity of replacing tabs with spaces for the split, but what
happened to the ER and the ° ?

input:

Sun 20h 38m 32s -18° 27.9' 0.985 -11.352 75.301 Set
Mercury 19h 39m 38s -17° 59.0' 0.693 -22.929 83.538 Set
Venus 23h 35m 40s -1° 34.9' 0.595 32.958 60.291 Up
Moon 21h 10m 19s -15° 43.1' 62.6 ER -3.535 73.245 Set
Mars 19h 41m 30s -22° 18.7' 2.365 -24.747 79.217 Set
Jupiter 20h 30m 0s -19° 26.4' 6.089 -13.572 75.592 Set
Saturn 11h 30m 54s +5° 29.7' 8.641 -29.340 -121.942 Set
Uranus 23h 25m 10s -4° 33.4' 20.808 29.003 59.973 Up
Neptune 21h 43m 4s -14° 4.9' 30.978 3.795 69.844 Up
Pluto 18h 8m 27s -17° 44.7' 32.385 -41.418 97.063 Set

output:

Sun 20 38 32 -18 27.9 0.985 -11.352 75.301 Set
Mercury 19 39 38 -17 59.0 0.693 -22.929 83.538 Set
Venus 23 35 40 -1 34.9 0.595 32.958 60.291 Up
Moon 21 10 19 -15 43.1 62.6 -3.535 73.245 Set
Mars 19 41 30 -22 18.7 2.365 -24.747 79.217 Set
Jupiter 20 30 0 -19 26.4 6.089 -13.572 75.592 Set
Saturn 11 30 54 +5 29.7 8.641 -29.340 -121.942 Set
Uranus 23 25 10 -4 33.4 20.808 29.003 59.973 Up
Neptune 21 43 4 -14 4.9 30.978 3.795 69.844 Up
Pluto 18 8 27 -17 44.7 32.385 -41.418 97.063 Set

--
larry gates

We question most of the mantras around here periodically, in case
you hadn't noticed. :)
-- Larry Wall in <[email protected]>
 
T

Tim Greer

Americans, your all the same.
Am Bushed once, er, remember that, er,
am Bushed twice, er, forget me not...

Americans are the 'decider', makes me puke..

sln

Do you suppose you are making a valid (or sane) point, by accusing 300+
million people of "all being the same"?
 
L

Larry Gates

AAAAARRRRRRRGGGGGGGG!!!!! HHHHHHEEEEEELLLLPPPPP!!!

Who on earth said anything about using STDOUT as a temp file? You asked
why you got output and I answered that specific question by telling you
that print() defaults to STDOUT if no other filehandle is specified (and
implied that STDOUT is opened automatically at the start of any
program).

What the devil moved you to turn STDOUT into a temp file? Nobody ever
suggested something so stupid! Do you know what STDOUT is? You are
claiming to be familiar with C. I cannot believe that, considering that
stdout is a concept coming from C.

jue

I had no explanation why I was getting output at all, given that I wasn't
writing to the file. I thought I was reading what had gone to stdout
earlier in the program. Yes, this notion was completely errant and points
to an uncareful reading of your post. On reflection, the reason I was
getting output was that I'd run the script before, so there already existed
a file that I thought I was creating every time.

Much of perl emulates the way the Bourne shell works, where it is trivial
to pipe STDOUT. So many things work "magically" around here; I thought it
was another example.

While I tried to do that, unsuccessfully, I successfully read portions of
perldoc perlvar, perldoc perlrun, and studied several functions in the
camel book. These are not the habits of a dullard.
 
L

Larry Gates

OK. Here is a quick version of your program with most of the logic
errors removed. Since I did test it, there still may be bugs, but it
should give you the overall logic flow:

use strict;
use warnings;

# open input file
my $filename = 'eph6.txt';
open(my $fh, '<', $filename) or
die "cannot open $filename for reading: $!";

# open output file
my $filename2 = 'outfile1.txt';
open(my $gh, '>', $filename2) or
die "cannot open $filename2 for writing: $!";

# process all lines in input file
while( my $line = <$fh> ) {
chomp($line);
my @s = split /\s+/, $line;

# modify fields
$s[1] =~ s/h//;
$s[2] =~ s/m//;
$s[3] =~ s/s//;
$s[5] =~ s/'//;

# print modified fields
for my $i (0..$#s) {
print "s[$i] = $s[$i]\n";
}

# write modified fields to output file
my $outline = join(' ', @s);
print $gh "$outline\n";
}

# close input and output files
close($gh) or die("Error closing $filename2: $!");
close($fh) or die("Error closing $filename: $!");

__END__

Note that aside from your explicit field modifications, this program
will compress two or more spaces in your input file to one space. If
this is a problem, then you should consider using unpack on the input
data and pack for the output data.

Hope this helps.

It does. I appreciate your comment. What this illustrates is what I
thought I was going to run into with my NOOP lines:

C:\MinGW\source>perl reg14.pl
s[0] = Sun
s[1] = 20
s[2] = 38
s[3] = 32
....
s[0] = Moon
s[1] = 21
s[2] = 10
s[3] = 19
s[4] = -15
s[5] = 43.1
s[6] = 62.6
s[7] = ER
s[8] = -3.535
s[9] = 73.245
s[10] = Set
....
s[0] = Pluto
s[1] = 18
s[2] = 8
s[3] = 27
s[4] = -17
s[5] = 44.7
s[6] = 32.385
s[7] = -41.418
s[8] = 97.063
s[9] = Set

C:\MinGW\source>type outfile10.txt
Sun 20 38 32 -18 27.9 0.985 -11.352 75.301 Set
Mercury 19 39 38 -17 59.0 0.693 -22.929 83.538 Set
Venus 23 35 40 -1 34.9 0.595 32.958 60.291 Up
Moon 21 10 19 -15 43.1 62.6 ER -3.535 73.245 Set
Mars 19 41 30 -22 18.7 2.365 -24.747 79.217 Set
Jupiter 20 30 0 -19 26.4 6.089 -13.572 75.592 Set
Saturn 11 30 54 +5 29.7 8.641 -29.340 -121.942 Set
Uranus 23 25 10 -4 33.4 20.808 29.003 59.973 Up
Neptune 21 43 4 -14 4.9 30.978 3.795 69.844 Up
Pluto 18 8 27 -17 44.7 32.385 -41.418 97.063 Set

C:\MinGW\source>

Here we see the black-shaded character that dos renders upper-ascii as, as
well as an eleventh field for the ER in the moon, which is definitely
trouble.

I would think that adding

$line =~ s/ER//g;
$line =~ s/œ//g;

would be the fix, but clearly there's another way that obviates this.

I just don't why.
 
L

Larry Gates

I guess this explains your "160+ IQ" at work, huh?

Tim,

I'd appreciate if you didn't respond to someone I, as OP, killfiled on this
thread. Thx.
--
larry gates

: I've heard that there is a shell (bourne or csh) to perl filter, does
: anyone know of this or where I can get it?
Yeah, you filter it through Tom Christiansen. :) -- Larry Wall
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top