B
Berk Birand
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
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