CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Extract from text file, basic trig functions, then graph: Edit Log


Oct 18, 2017, 8:24 AM

Views: 37342
Extract from text file, basic trig functions, then graph

Hi there,

Complete noob. Trying to extract some positions from a text file (easting and northing), then do some basic trigonometry. I have multiple issues, the first being the extraction. The below is what I am using for a fixed string:


my $filename = 'R001.txt';
open (my $fh, '>', $filename) or die "Could not open file '$filename' $!";

while ( <> )
if ( /R 1/ )
$easting = substr($_,6,8);
$northing = substr($_,14,9);

print $fh "$easting,$northing\n";
close $fh

Ideally what I would like to do is read an input file with an external lookup search list, and output each to the same file name. In the above example it is looking for R 1 (for some reason this file does not pad with leading zeros), and output to R001.txt

The second thing I want to do is subtract the eastings and northings from each line to get delta eastings & delta northings, and then calculate some other attributes (azimuth etc).

Now, I am not sure if I should first get these into readable files, so that we are not reading the same input over and over again. What I am suggesting, is that maybe the output file should be:

easting (1), northing (1), easting (2), northing (2)

So that the next parse of the file can do the trigonometry in one line step (hope that makes sense)?

I think for now I should just concentrate on getting the output correct, rather than the math, so if anyone can help it would be much appreciated.

I've attached a sample file. Ideally I would like to extract the following:

R   1 
R 564
R 565

and so on, but like I say, maybe an external lookup file would be the best option (because then I can just edit it to suit as I need).

Thanks in advance.

(This post was edited by marky9074 on Oct 19, 2017, 1:51 AM)
Attachments: Sample.txt (216 KB)

Edit Log:
Post edited by marky9074 (Novice) on Oct 19, 2017, 1:51 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives