Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I am very new at this and I am looking for a lot of help. I have data that I need to extract values from, perform calculations and then write to another file.

I would like to write all of the x,y values for the POINTs to File2 and all the VERTEX x,y values to File1. The x value is on line 4 from both VERTEX and POINT and the y value on line 6 from both VERTEX and POINT.

So File1 is a list of VERTEX and looks like
vx1, vy1
vx2, vy2
vx3, vy3
vx4, vy4
vx5, vy5
vx6, vy6
... and File2 is a list of POINTs and looks like
xp1, yp2
xp2, yp2
... Every xp1, yp1 in File2 is also located in File1. I need to find these points xp1, yp1 in File1, delete it, and replace it with two new values, a new vx, vy.

example--- xp1, yp1 is the same value as vx3, vy3. I need vx2, vy2 and vx4, vy4 to do calculations. Then I need to delete vx3, vy3 and replace it with vx31, vy31 and vx32, vy32.

Below is the same data that I am using and what values I need. Thanks for your help and I hope to hear from you soon. > > example
> > VERTEX
> > 8
> > 1
> > 10
> > 440.5282 26 (Vertex vx1)
> > 20
> > 267.931852 (Vertex vy1)
> > 0
> > VERTEX
> > 8
> > 1
> > 10
> > 903.665710 (Vertex vx2 - x1 value for > > calculation)
> > 20
> > 424.695464 (Vertex vy2 - y1 value for > > calculation)
> > 0
> > VERTEX
> > 8
> > 1
> > 10
> > 851.607625 (Vertex vx3 - Also POINT xp1)
> > 20
> > 496.102325 (Vertex vy3 - Also POINT yp1)
> > 0
> > VERTEX
> > 8
> > 1
> > 10
> > 828.895143 (Vertex vx4 - x2 value for > > calculation)
> > 20
> > 526.760804 (Vertex vy4 - y2 value for > > calculation)
> > 0
> > VERTEX
> > 8
> > 1
> > 10
> > 401.846293 (Vertex vx5)
> > 20
> > 382.212539 (Vertex vy5)
> > 0
> > VERTEX
> > 8
> > 1
> > 10
> > 440.528226 (Vertex vx6 - same as vx1-completes > > loop)
> > 20
> > 267.931852 (Vertex vy6 - same as vy1-completes > > loop)
> > 0
> > SEQEND
> > 0
> > POINT
> > 8
> > 4
> > 10
> > 851.607625 (POINT xp1)
> > 20
> > 496.102325 (POINT yp1)
> > 50
> > 214.96
> > 0
> > ENDBLK

edited: Sat Feb 1 16:03:10 2003 by jeffa - title change (was: Please help)

Replies are listed 'Best First'.
Re: Basic file processing
by ibanix (Hermit) on Feb 01, 2003 at 00:24 UTC
    Hi AnonyMonk,

    You'll want to start writing some code. Here's something to get you started:
    # Set your input and output file my $inputfile = "input.txt"; my $outputfile = "output.txt"; # Open your input file open(my $input, $inputfile); # Open your output file, for writing open(my $output, ">$outputfile"); # Read each line in, one at a time while(<$input>) { # Here's where you put your personal logic # When you need to print to the output file, do this # The $_ means, in this case only, "current line" print $output "Hey, I found $_\n"; } # Close your files when done! close($input); close($output);
    There is plenty of online documentation to get you started. You may also want to read the introduction to Perl.

    Good luck. If you have more questions, post them here, and please include your code.

    Cheers,
    ibanix

    $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
Re: Basic file processing
by Marza (Vicar) on Feb 01, 2003 at 00:04 UTC

    Some code would be nice. Have you even started? Post what you have and don't forget to use the codetags around the source.