2012-02-20 11:50:05 +00:00
|
|
|
#!/usr/bin/perl -i
|
2011-12-10 21:22:14 +00:00
|
|
|
|
|
|
|
use strict;
|
2012-02-20 11:50:05 +00:00
|
|
|
use warnings;
|
2011-12-10 21:22:14 +00:00
|
|
|
|
|
|
|
my $z = 0;
|
|
|
|
|
2011-12-10 21:27:16 +00:00
|
|
|
# read stdin and any/all files passed as parameters one line at a time
|
2012-02-20 11:50:05 +00:00
|
|
|
while (<>) {
|
2011-12-10 21:27:16 +00:00
|
|
|
# if we find a Z word, save it
|
2012-09-26 08:49:42 +00:00
|
|
|
$z = $1 if /Z\s*(\d+(\.\d+)?)/;
|
2011-12-10 21:27:16 +00:00
|
|
|
|
|
|
|
# if we don't have Z, but we do have X and Y
|
|
|
|
if (!/Z/ && /X/ && /Y/ && $z > 0) {
|
|
|
|
# chop off the end of the line (incl. comments), saving chopped section in $1
|
2012-09-26 08:49:42 +00:00
|
|
|
s/\s*([\r\n\;\(].*)/" Z$z $1"/es;
|
2011-12-10 21:27:16 +00:00
|
|
|
# print start of line, insert our Z value then re-add the chopped end of line
|
2012-09-26 08:49:42 +00:00
|
|
|
# print "$_ Z$z $1";
|
2011-12-10 21:22:14 +00:00
|
|
|
}
|
2012-09-26 08:49:42 +00:00
|
|
|
#else {
|
2011-12-10 21:27:16 +00:00
|
|
|
# nothing interesting, print line as-is
|
2012-09-26 08:49:42 +00:00
|
|
|
print or die $!;
|
|
|
|
#}
|
2011-12-10 21:22:14 +00:00
|
|
|
}
|