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 3 2328
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
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.
In article <41******************************@news.teranews.co m>, Berk
Birand <gr************@NOSPAMyahoo.com> wrote: 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
You should let Perl help you while you are developing code:
use strict;
use warnings;
open(HELL,"plc") or die "Can't open plc: $!"; my @x; my @y;
#first read the file #put the coordinates in special variables
my $i = 0; #(see below)
while (<HELL>) { # assigns each line in turn to $_ $_ =~ /(\d+),(\d+)/;
Always check to see if the match worked before using the results:
if( /(\d+), (\d+)/ ) { for($i=0; $i<=3;$i++) {
Why are you assigning the extracted coordinates 4 times?
@x[$i] = [ $1 ] ;
This is assigning a reference to an array of one element ( [ $1 ] ) to
an array slice of one element ( @x[$i] ). This is not likely to be what
you want. @y[$i] = [ $2 ];
Maybe you want just:
$x[$i] = $1;
$y[$i] = $2;
$i++;
where you refer to the n'th element of @x as $x[n]. If so, then you
need the declaration of $i above, before and outside the loop. 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 # [...] }
Now you can do a calculation with the contents of @x and @y:
for my $i ( 0 .. $#x ) {
print "$x[$i], $y[$i]\n";
}
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Suresh Kumar |
last post by:
Hi,
In Tkinter, how to convert canvas coordinates to window
coordinates? To convert window coordinates to canvas coordinates
we are using "canvasx,canvasy". But how to do vice-versa? Iam
using a...
|
by: Oldchatterman |
last post by:
Hello,
in an application I measure a lot of 2d coordinates (x,y) of a
pattern. This pattern consists of a set of points on grid with fixed
pitches in x and y direction. These coordinates all...
|
by: Stacey |
last post by:
I've been trying for the last couple of days to read some pixel values
from a window of an independent application, but, even though I got
close, I just can't figure the last part out.
I am able...
|
by: steve |
last post by:
Hi All
I have textboxes within a TableLayoutpanel and I want to be able to position
an independant control adjacent to a selected textbox
This independent control allows selection of text to...
|
by: tonnyspain |
last post by:
Hi,
I am new to c++ programming.Could anyone tell me how I can use
standard input in c++ to read 2D coordinates? e.g., read n elements
which have x-coordinates and y-coordinates.
Could anyone...
|
by: Cainnech |
last post by:
Hi all,
I've got a bit of a challenge. I've got a script which displays the mouse coodinates if you click on an image. Now I would like to convert these coordinates to pixelnumber. Let me see if I...
|
by: raylopez99 |
last post by:
keywords: logical coordinates, page coordinates, world coordinates,
device coordinates, physical coordinates, screen coordinates, client
coordinates. offset rectangle. WYSIWYG rubber rectangle...
|
by: mingke |
last post by:
Hi....
I'm having difficulties with my codes to list coordinates (in my example codes is 4x4 pixel). I tried two different codes and the results are different.Basically, I tried to declare the sub...
|
by: kennypt |
last post by:
Hi all, this is my first post, i have a little problem.
I'm tryign to read a specific atribute from a xml website using this code:
...
'this is the url im trying to read, tmpIn is a string...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |