From: Joseph L. Casale [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 11, 2007 1:51 PM To: beginners@perl.org Subject: Search and Replace
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! Thanks guys! jlc maybe ... while (my $dat = <SOMEINPUT>) { $dat =~ /^\s+(.*)\s+^/\1/g; my ($x,$y,$z) = split /\s+/; print SOMEFILE "X$x Y$y Z$newz\n"; } ... Hope this helps... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/