File: z-every-line.pl

package info (click to toggle)
slic3r 1.3.0%2Bdfsg1-5.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,552 kB
  • sloc: cpp: 63,126; perl: 21,512; ansic: 6,312; sh: 591; xml: 201; makefile: 37; python: 11
file content (24 lines) | stat: -rwxr-xr-x 589 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/perl -i

use strict;
use warnings;

my $z = 0;

# read stdin and any/all files passed as parameters one line at a time
while (<>) {
	# if we find a Z word, save it
	$z = $1 if /Z\s*(\d+(\.\d+)?)/;

	# 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
		s/\s*([\r\n\;\(].*)/" Z$z $1"/es;
		# print start of line, insert our Z value then re-add the chopped end of line
		# print "$_ Z$z $1";
	}
	#else {
		# nothing interesting, print line as-is
	print or die $!;
	#}
}