Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Swap Ascii chr() for null string

by ikegami (Patriarch)
on Sep 15, 2017 at 20:57 UTC ( [id://1199481]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1199481]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 12:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found