in reply to Swap Ascii chr() for null string

Works for me.

$ perl -e' my $String = "xxxchr12yyy"; $String =~ s/chr(12)//g; CORE::say $String; ' xxxyyy

Replies are listed 'Best First'.
Re^2: Swap Ascii chr() for null string
by PriNet (Monk) on Sep 15, 2017 at 20:59 UTC
    not the string 'chr12', the ascii character (12)...

    Has anyone seen this sliced bread thing? I's better than... sliced... well... never mind...

      But you told it to match the string chr12! You can't place code in a string literal and expect it to be executed.

      You want any of the following:

      s/\014//g; # By octal s/\x0C//g; # By hex s/\x{C}//g; # By hex (leading zeros allowed) s/\N{U+C}//g; # By hex (leading zeros allowed) s/\N{FORM FEED}//g; # By name s/\N{FF}//g; # By alias

      You could also use the character literally.

      my $ff = chr(12); s/\Q$ff\E//g;

      PriNet:

      You can't have arbitrary code in the left of a substitution regular expression. (If you use the e modifier, though, you can do so on the right side.)

      So you either need to use interpolation:

      $form_feed = chr(12); $var =~ s/$form_feed//g;

      Or you can just specify the value using a hex or octal literal \x0c or \014:

      $var =~ s/\014//g;

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.