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 $!; } }

In reply to Re^2: How to search and replace text characters in a perl script by thetekguy
in thread How to search and replace text characters in a perl script by thetekguy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.