thetekguy has asked for the wisdom of the Perl Monks concerning the following question:
Sample Data:#!/usr/bin/perl -i.before_postproc # Author : David Sherwood # Version : 1.0 # Copyright : none. # # Slice3R GCODE laser cutter post-processor use strict; use warnings; # read stdin and any/all files passed as parameters one line at a time while (<> ) { if (/G11/) { # if we have an un-retraction line, replace it with laser powe +r on print "M400 ; wait for moves to finish\nM104 S100 ; laser on\n +"; } elsif (/G10/) { # if we found a retraction line, replace it with laser power o +ff print "M104 S0 ; laser off\n"; } elsif (/G92/) { # if we found an extruder reset command line, remove it print ""; } elsif (/M190/) { # if we found a heat bed command line, remove it print ""; } else { print or die $!; } }
Expected DataG92 E0 ; want to remove all G92 lines (works now) T1 G1 Z0.050 F7800.000 G10 ; retract G92 E0 G1 Z0.150 F7800.000 G1 X14.725 Y-8.975 F7800.000 G1 Z0.050 F7800.000 G11 ; unretract G92 E0 G1 X14.725 Y8.975 E0.01465 F120.000 G10 ; retract G92 E0 G1 Z0.150 F7800.000 G1 X-9.585 Y-0.615 F7800.000 G1 Z0.050 F7800.000 G11 ; unretract G92 E0
T1 G1 Z-0.050 F7800.000 M104 S0 ; laser off G1 Z-0.150 F7800.000 G1 X14.725 Y-8.975 F7800.000 G1 Z-0.050 F7800.000 M400 ; wait for moves to finish M104 S100 ; laser on G1 X14.725 Y8.975 F120.000 M104 S0 ; laser off G1 Z-0.150 F7800.000 G1 X-9.585 Y-0.615 F7800.000 G1 Z-0.050 F7800.000 M400 ; wait for moves to finish M104 S100 ; laser on
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to search and replace text characters in a perl script
by stevieb (Canon) on May 19, 2016 at 22:23 UTC | |
by AnomalousMonk (Archbishop) on May 20, 2016 at 06:11 UTC | |
by thetekguy (Initiate) on May 20, 2016 at 03:14 UTC | |
|
Re: How to search and replace text characters in a perl script
by graff (Chancellor) on May 20, 2016 at 02:56 UTC | |
by thetekguy (Initiate) on May 20, 2016 at 03:20 UTC | |
|
Re: How to search and replace text characters in a perl script
by Marshall (Canon) on May 20, 2016 at 02:54 UTC |