in reply to Re: How to search and replace text characters in a perl script
in thread How to search and replace text characters in a perl script

Beautiful! Thanks for the quick response. It would have taken me weeks of trial and error to get to this point- but this helps me learn for next time. Much appreciated! Here is the final working code:
#!/usr/bin/perl -i.before_postproc # Author : David Sherwood # Version : 1.0 # Copyright : none. # # Postprocessor for Slic3R Gcode for Laser Cutter use strict; use warnings; # read stdin and any/all files passed as parameters one line at a time while (<>) { chomp; # EN.NNNNN # no need for if(), we're not using the capture number vars s/E\d\.\d{5}//; # ZNN.NNN # need if, or it'll warn on no match if (/G1 Z\d{1,2}\.\d{3}/){ s/(G1 Z)(\d{1,2}\.\d{3})/$1-$2/; } 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 "$_\n" or die $!; } }