Joseph L. Casale wrote:
Hi,
Know that I am learning perl, I am expected to use it at work :)
Problem is I am still to green for the current problem I have. The data is
always left justified and has a space between each value.
I have a text file of about ~500 lines like this:
-11.67326 23.95923 0.4617566
5.075023 24.27938 0.4484084
6.722163 -24.68986 1.399011
-11.2023 -25.0398 1.145933
I need to do the following:
Insert and X, Y and Z as one script:
X-11.67326 Y23.95923 Z0.4617566
X5.075023 Y24.27938 Z0.4484084
X6.722163 Y-24.68986 Z1.399011
X-11.2023 Y-25.0398 Z1.145933
Lastly, I'll need to make an additional copy of the program to strip out any
numerical values for Z, and replace them with the following, [some_var].
X-11.67326 Y23.95923 Z[some_var]
X5.075023 Y24.27938 Z[some_var]
X6.722163 Y-24.68986 Z[some_var]
X-11.2023 Y-25.0398 Z[some_var]
Any help would be appreciated greatly, I am still just to new for this!
How about the program below? For your final variation, just change the line
printf "X%s Y%s Z%s\n", @data;
to
printf "X%s Y%s Z[some_var]\n", @data;
And note that you could open two output files and write to them both
using two print statements, rather than running a different program to
create the second file.
Hope this helps.
Rob
use strict;
use warnings;
while (<DATA>) {
my @data = split;
printf "X%s Y%s Z%s\n", @data;
}
__DATA__
-11.67326 23.95923 0.4617566
5.075023 24.27938 0.4484084
6.722163 -24.68986 1.399011
-11.2023 -25.0398 1.145933
**OUTPUT**
X-11.67326 Y23.95923 Z0.4617566
X5.075023 Y24.27938 Z0.4484084
X6.722163 Y-24.68986 Z1.399011
X-11.2023 Y-25.0398 Z1.145933
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/