I would like to replace the line in the my text file mathematically as follows,
TRANS -20.0 -30.0 -40.0
There are 4 blank spaces before TRANS and again 4 blank spaces between the numbers.
I use the code and get the following output
TRANS -13.0 -28.0 -31.0
Expand|Select|Wrap|Line Numbers
- #!\usr\bin\perl
- use warnings;
- use strict;
- open IN,"+< z.txt";
- open OUT,"> t.txt";
- while (<IN>) {
- $file =~ s/\s+(\S+)\s+(-?\d+\.?\d?)\s+(-?\d+\.?\d?)\s+(-?\d+\.?\d?)/printf " $1 %.1f %.1f %.1f", $2+7,$3+2,$4+9/eg;
- print OUT;
- }
2. My other question is that if there are positive numbers in the input for eg
TRANS 20.0 30.0 40.0
I would like to have the numbers fixed in the respective position as this text file forms the input for other external programs. Therefore I need to maintain the position of the numbers like 20.0 and the last 0 should always be in 17th column and also 40.0 and the last zero must be in 37th column. If there are negative numbers as in the earlier case, the sign should be shown without altering the position of numbers. Is there anyway of representing this.
Ramesh