Read coordinates

Discussion in 'Perl' started by Berk Birand, Mar 6, 2004.

  1. Berk Birand

    Berk Birand Guest

    Hi,

    I am new to Perl (as a matter of fact, I started learning it a couple of
    days ago; I have some previous programming experience though). When
    looking for the ideal languages to use for a particular project, I came
    across perl, and starting writing the script.

    I need to read a text containing some coordinates:
    248,156
    322,156
    326,368
    248,368

    326,194
    950,194
    960,360
    326,364

    ....

    I need to process these coordinates and find the center of gravity of the
    structure.

    For now I have this code.

    #! /usr/bin/env perl

    open(HELL,"plc") or die "Can't open plc: $!";
    my @x;
    my @y;

    #first read the file
    #put the coordinates in special variables

    while (<HELL>) { # assigns each line in turn to $_
    $_ =~ /(\d+),(\d+)/;

    for($i=0; $i<=3;$i++) {
    @x[$i] = [ $1 ] ;
    @y[$i] = [ $2 ];

    print $x[1]; }

    # print "the x is $1 \n";
    # print "the y is $2 \n";
    # print "Just read in this line: $_";

    # do the necessary calculations
    # [...]
    }
    I thought about putting each coordinate in an array of x and y values, and
    then finding their arithmetic means.
    However I do not know how to augment the arrays size at each iteration of
    while. The size of the array cannot be changed can it?
    Help would be greatly appreciated!

    Thanks

    BB
     
    Berk Birand, Mar 6, 2004
    #1
    1. Advertising

  2. Berk Birand wrote:
    [...]
    > However I do not know how to augment the arrays size at each
    > iteration of while. The size of the array cannot be changed can it?


    I think you are looking for the push() function, see "perldoc -f push"

    jue
     
    Jürgen Exner, Mar 7, 2004
    #2
    1. Advertising

  3. Berk Birand

    Berk Birand Guest

    On Sun, 07 Mar 2004 00:25:49 +0000, Jürgen Exner wrote:
    > I think you are looking for the push() function, see "perldoc -f push"


    Yes, that solved the problem quite well.
    Thanks Jürgen.
     
    Berk Birand, Mar 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    21,566
    Jim Gibson
    Nov 4, 2003
  2. Stimp

    coordinates of a DIV

    Stimp, Sep 22, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    28,513
    David Jessee
    Sep 22, 2004
  3. Dan Sikorsky

    HOWTO: Get Web Control Screen Coordinates

    Dan Sikorsky, Nov 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,815
    Dan Sikorsky
    Nov 12, 2004
  4. Suresh  Kumar
    Replies:
    0
    Views:
    616
    Suresh Kumar
    Jul 3, 2003
  5. Suresh  Kumar
    Replies:
    0
    Views:
    536
    Suresh Kumar
    Jul 4, 2003
Loading...

Share This Page