perl command to read the coordinate {x1 y1} {x2 y2}
Hi.. i have an question about perl command. I have a data that look like this which in term of {x1 y1} {x2 y2}
{1111.6788 2234.8769} {1121.6788 2244.8769}
{2344.6756 2268.9978} {2354.6756 2278.9978}
how do i want to read the data in perl command by multiple x1 with 2 and y1 with 3.
- read the data of x1, y1, x2 and y2 separately.
- X1 multiple with 2 ,y1 multilple with 3, X2 plus with 10 and Y2 also plus with 10
- save the answer inside the file in this format again {X1 Y1} {X2 Y2}
I will apppriciate it if u can help me :)
Thank you
• 1,230 views
•
link
1 answer
the following perl snippet should work :
#! /usr/bin/env perl
use strict;
use warnings;
while (<STDIN>){
$_ =~ s/[{}]//g;
my @line = split (' ', $_);
$line[0] = $line[0] *2;
$line[1] = $line[1] *3;
$line[2] += 10;
$line[3] += 10;
print "{$line[0] $line[1]} {$line[2] $line[3]}\n";
}
it reads from STDIN and prints out the values tab-delineated for now (not sure what you want/have):
{2223.3576 6704.6307} {1131.6788 2254.8769}
{4689.3512 6806.9934} {2364.6756 2288.9978}
• 1 views
•
link
Log in to answer this question.