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

# need if, or it'll warn on no match

No need: no substitution is done, no capture variables are referenced, if no replacement match exists:

c:\@Work\Perl\monks>perl -wMstrict -le "for my $s ('G1 Z0.050 F7800.000', 'G10 ; retract',) { printf qq{'$s' -> }; local $_ = $s; s/(G1 Z)(\d{1,2}\.\d{3})/$1-$2/; print qq{'$_'}; } " 'G1 Z0.050 F7800.000' -> 'G1 Z-0.050 F7800.000' 'G10 ; retract' -> 'G10 ; retract'
(Although I think I would prefer to use look-arounds as graff did and just stick a - in.)


Give a man a fish:  <%-{-{-{-<