Re: inputting the ephemerides



On Wed, 21 Jan 2009 19:59:59 -0800, Jürgen Exner wrote:

Larry Gates <larry@xxxxxxxxxxxxxxx> wrote:
How would you get rid of the ° and the ' and leave the -44.6 in the
following:
° -44.6'

On way:
my $s = substr('° -44.6\'', 1, length($t)-2);

Another way
my @s = split(//,'° -44.6\'');
my $s = join('', @s[1..$#s-1]);


Or you could play the old
chop
reverse
chop
reverse
trick.

I'm sure there are many more ways to remove the first and last character
of a string.

jue

Thanks jü. Now that we're a little farther down the road, I've found
another way to deal with ° /t and ER, which were the troublemakers for
these data:

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;
print $gh $line;
print STDOUT $line;
}
close($fh);

# seek($fh,0,0);

close($gh);

# perl reg1.pl


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

Now, all the terms are delimited by / /; the characters are all ascii; the
ER after the moon is gone, so there is the same number of terms per line.

Wouldn't a split work well here?
--
larry gates

/* This bit of chicanery makes a unary function followed by
a parenthesis into a function with one argument, highest precedence. */
-- Larry Wall in toke.c from the perl source code
.