Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > inputting the ephemerides

Reply
Thread Tools

inputting the ephemerides

 
 
Larry Gates
Guest
Posts: n/a
 
      01-20-2009

Happy Bye George Day!

I've been chipping away at a long-term project: investigating the
ephemeris. I think it would make a great way to continue exploring perl's
pattern-matching capabilities.

So I'll have a program that looks like this:

my $filename = 'eph3.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
while (<$fh>) {
print $_;
}
close($fh)

# perl faulk10.pl

or

open(my $fh, '<', 'eph3.txt');
while (my $line = <$fh>) {
print $line;
}
close($fh)

# perl faulk7.pl

I'll want to have an explicit variable for the line, so I'll use the better
parts of the above.

The first thing I'll want to do is capture the first seven characters in a
line. We can assume that these will always be letters or spaces padded out
to the right.

After that, I want to strip away all the characters, as does the following
fortran routine. In this treatment $line would be inrec .

subroutine WasteNonDigits(inrec)
character*80 inrec
character*1 c1,c2
character*13 ValidDigits
data ValidDigits/'0123456789.-+'/
n=13
do i=1,80
c1=' '
c2=inrec(i:i)
do j=1,n
if(c2.eq.ValidDigits(j:j)) c1=c2
end do
inrec(i:i)=c1
end do
return
end subroutine

Ultimately, I want to populate an object that I think would be pretty tame
by perl standards.

This is the data set:

C:\MinGW\source>type eph3.txt
! yesterday
# another comment

Sun 18h 41m 55s -23 5.4' 0.983 10.215 52.155 Up
Mercury 20h 2m 16s -22 12.5' 1.102 22.537 37.668 Up
Venus 21h 55m 33s -14 16.3' 0.795 39.872 11.703 Up
Moon 21h 17m 19s -15 2.4' 62.4 ER 36.796 22.871 Up
Mars 18h 11m 59s -24 6.1' 2.431 4.552 56.184 Up
Jupiter 20h 3m 35s -20 49.4' 6.034 23.867 38.203 Up
Saturn 11h 32m 59s +5 8.6' 9.018 -47.333 157.471 Set
Uranus 23h 21m 30s -4 57.9' 20.421 48.328 -18.527 Up
Neptune 21h 39m 30s -14 22.8' 30.748 38.963 16.599 Up
Pluto 18h 4m 34s -17 44.5' 32.543 7.443 62.142 Up

C:\MinGW\source>

Thanks for your comment.
--
larry gates

You know how people are sometimes rude on Usenet or on a mailing list.
Sometimes they'll write something that can only be taken as a deadly
insult,
and then they have the unmitigated gall to put a smiley face on it, as if
that makes it all right. -- Larry Wall, 8th State of the Onion
 
Reply With Quote
 
 
 
 
Jrgen Exner
Guest
Posts: n/a
 
      01-20-2009
Larry Gates <(E-Mail Removed)> wrote:
>So I'll have a program that looks like this:
>
> my $filename = 'eph3.txt';
> open(my $fh, '<', $filename) or die "cannot open $filename: $!";
> while (<$fh>) {
> print $_;
> }
> close($fh)


Not much of a program, don't you think?

> open(my $fh, '<', 'eph3.txt');


You are missing error handling

> while (my $line = <$fh>) {
> print $line;
> }
> close($fh)


You know, this is terribly similar to something I have seen a few weeks
ago from some George character. Are you sure you are not suffereing from
Dissociative Identity Disorder?

>I'll want to have an explicit variable for the line, so I'll use the better
>parts of the above.
>
>The first thing I'll want to do is capture the first seven characters in a
>line.


See "perldoc -f substr".

>After that, I want to strip away all the characters, as does the following
>fortran routine. In this treatment $line would be inrec .


And what exactly does that Fortran routine do? Not everyone speaks
Fortran, therefore an abstract specification or at least a detailed
description would be much better than dumping some code in some foreign
programming language.

Again, that George was dumping Fortran code into this NG, too.

>Ultimately, I want to populate an object that I think would be pretty tame
>by perl standards.


And what would that object be? An AoA? An A0H? A HoH?

jue
 
Reply With Quote
 
 
 
 
Tim Greer
Guest
Posts: n/a
 
      01-20-2009
Jrgen Exner wrote:

> You know, this is terribly similar to something I have seen a few
> weeks ago from some George character


He was George, said he was changing his posting name in celebration of
George being out of office. I also can't wrap my head around his
example of posting code that opens a file and prints and then another
snippet basically being the same, just without error checking. Weird.
I stopped reading and moved on.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      01-20-2009

Larry Gates wrote:
[...]
>
> Thanks for your comment.


I didn't see any questions.

Good luck with your project.

--
RGB
 
Reply With Quote
 
George
Guest
Posts: n/a
 
      01-20-2009
On Mon, 19 Jan 2009 23:08:09 -0800, Tim Greer wrote:

> J�Exner wrote:
>
>> You know, this is terribly similar to something I have seen a few
>> weeks ago from some George character

>
> He was George, said he was changing his posting name in celebration of
> George being out of office. I also can't wrap my head around his
> example of posting code that opens a file and prints and then another
> snippet basically being the same, just without error checking. Weird.
> I stopped reading and moved on.


Between the responses no source survived, so you can't wonder too much why
context is a problem.

Here's the resolution of your "weirdness:"

my $filename = 'eph3.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";

while (my $line = <$fh>){

print $line;
}
close($fh)

# perl faulk11.pl
--
George

You can fool some of the people all the time, and those are the ones you
want to concentrate on.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
Reply With Quote
 
Larry Gates
Guest
Posts: n/a
 
      01-20-2009
On Tue, 20 Jan 2009 10:34:56 +0000, RedGrittyBrick wrote:

> Larry Gates wrote:
> [...]
>>
>> Thanks for your comment.

>
> I didn't see any questions.
>
> Good luck with your project.


I guess I didn't.

I was fishing for a perl method to deliver only the numbers and whitespace.

--
larry gates

You don't have to wait--you can have it in 5.004_54 or so.
-- Larry Wall in <(E-Mail Removed)>
 
Reply With Quote
 
Tad J McClellan
Guest
Posts: n/a
 
      01-20-2009
Larry Gates <(E-Mail Removed)> wrote:


> The first thing I'll want to do is capture the first seven characters in a
> line.



my $first7 = substr $line, 0, 7;


> We can assume that these will always be letters or spaces padded out
> to the right.



If you want to validate the data against those criteria, then:

die "'$first7' is 'bad' data\n" unless $first7 =~ /^[a-z]+\s*$/i;


> After that, I want to strip away all the characters,



Errr... OK:

$first7 = '';

If you instead meant to say "strip away all the trailing space characters":

$first7 =~ s/\s+$//;


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
treybianchini@gmail.com
Guest
Posts: n/a
 
      01-20-2009
On Jan 20, 7:20*am, Tad J McClellan <(E-Mail Removed)> wrote:
> Larry Gates <(E-Mail Removed)> wrote:
> > The first thing I'll want to do is capture the first seven characters in a
> > line. *

>
> * * my $first7 = substr $line, 0, 7;
>
> > We can assume that these will always be letters or spaces padded out
> > to the right.

>
> If you want to validate the data against those criteria, then:
>
> * * die "'$first7' is 'bad' data\n" unless $first7 =~ /^[a-z]+\s*$/i;
>
> > After that, I want to strip away all the characters,

>
> Errr... OK:
>
> * * $first7 = '';
>
> If you instead meant to say "strip away all the trailing space characters":
>
> * * $first7 =~ s/\s+$//;
>
> --
> Tad McClellan
> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"



Maybe you meant 'strip away all of the non numeric characters'.
$first7 =~ s/\D//g;
That will also take out any periods and negative signs which you might
want so you might have to tailor the expression a bit more than that.

Perhaps you could split the lines of the input file into fields and
then write some conditional logic which might do different
substitutions based on what expression the data matches before you
populate your objects.

$field =~ s/\s//g;
if ( $field =~ /\d+\./ ) {
...
} elsif { $field =~ /^*\d+\D/ ) {

etc...

}

A really "great way to continue exploring perl's pattern-matching
capabilities" might be to go to

http://www.perl.com/doc/manual/html/pod/perlre.html

or type

perldoc perlre <enter>

or read your textbook more closely maybe?

Good luck,
Trey

 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      01-20-2009

Larry Gates wrote:
> On Tue, 20 Jan 2009 10:34:56 +0000, RedGrittyBrick wrote:
>
>> Larry Gates wrote:
>> [...]
>>> Thanks for your comment.

>> I didn't see any questions.
>>
>> Good luck with your project.

>
> I guess I didn't.
>
> I was fishing for a perl method to deliver only the numbers and whitespace.
>


perldoc -f substr
perldoc -f split

Assuming you don't mean
perl -p -e 's/[^\s\d]//g' ephemerides.txt

--
RGB
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      01-20-2009
George wrote:

> On Mon, 19 Jan 2009 23:08:09 -0800, Tim Greer wrote:
>
>> J�Exner wrote:
>>
>>> You know, this is terribly similar to something I have seen a few
>>> weeks ago from some George character

>>
>> He was George, said he was changing his posting name in celebration
>> of
>> George being out of office. I also can't wrap my head around his
>> example of posting code that opens a file and prints and then another
>> snippet basically being the same, just without error checking.
>> Weird. I stopped reading and moved on.

>
> Between the responses no source survived, so you can't wonder too much
> why context is a problem.
>
> Here's the resolution of your "weirdness:"
>
> my $filename = 'eph3.txt';
> open(my $fh, '<', $filename) or die "cannot open $filename: $!";
>
> while (my $line = <$fh>){
>
> print $line;
> }
> close($fh)
>
> # perl faulk11.pl


I saw your original post (I don't have you blocked). You posted a
portion of code, such as above, that goes through each line and prints
it. It's not really doing anything related to the task you asked
about. What was "weird" was that you posted the same code again (for
the most part), but just failed to check the return value of open and
didn't add $_ to print (since it wouldn't be needed -- it wasn't in the
first one either). I fail to understand the purpose of you doing that?
You then posted about what you wanted to do, but you didn't post any
code relevant to it to show us what you have tried. I admit, I thought
that was weird.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible inputting characters from keyboard by codes. yasin ASP .Net 1 04-20-2006 09:11 PM
Inputting Text to the Runtime Parser =?Utf-8?B?amFzb253b25n?= ASP .Net 0 01-13-2006 07:57 PM
Error on inputting data Aaron ASP .Net 3 01-02-2006 04:20 PM
Inputting Greek letter in textarea dungping HTML 27 09-02-2005 09:02 PM
Inputting NULLS? Bill ASP .Net 1 12-11-2003 07:29 PM



Advertisments