in reply to Re: Swap Ascii chr() for null string
in thread Swap Ascii chr() for null string

not the string 'chr12', the ascii character (12)...

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

Replies are listed 'Best First'.
Re^3: Swap Ascii chr() for null string
by ikegami (Patriarch) on Sep 15, 2017 at 21:08 UTC

    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;
Re^3: Swap Ascii chr() for null string
by roboticus (Chancellor) on Sep 15, 2017 at 21:12 UTC

    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.