What is the section above supposed to do?
It reads a line from a file into memory, alters the line, and then
happily throws it away by reading the next line without doing anything
with that altered line. This is a giant NOOP. Why are you doing that?
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
of nothing. (Douglas Hofstadter had his own clever alterations along these
lines, but that's a different story.)
I *do* use the $line, because that's what I split on:
my @s = split /\s+/, $line;
Apparently your original string contains consecutive sequences of space
characters. Your RE will split between each individual space, thus
creating numerous empty result strings.
If you don't want that then instead of splitting at a single space use
the whole consecutive sequence of space characters as the item to split
the original string at.
jue
Ok. It sometimes takes me a while to use some of the suggestions that you
(plural) give me. I was finally able to mimic the join syntax that you
(singular) posted at the top of this subthread, and I'm pleased to roll out
my first output that I can call a solution:
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;
}
close($fh);
seek($gh,0,0);
while (my $line = <$gh>) {
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";
}
$line = join(' ', @s[0..$#s]);
print "$line\n";
}
close($gh);
# perl reg9.pl
C:\MinGW\source>perl reg9.pl
s 0 is Sun
s 1 is 19
s 2 is 43
s 3 is 51
s 4 is -21
s 5 is 17.8
s 6 is 0.984
s 7 is -35.020
s 8 is 87.148
s 9 is Set
Sun 19 43 51 -21 17.8 0.984 -35.020 87.148 Set
...
s 0 is Pluto
s 1 is 18
s 2 is 6
s 3 is 40
s 4 is -17
s 5 is 44.9
s 6 is 32.485
s 7 is -52.833
s 8 is 108.052
s 9 is Set
Pluto 18 6 40 -17 44.9 32.485 -52.833 108.052 Set
C:\MinGW\source>