A little refinement.
On Tue, 6 Sep 2016 21:04:04 +0200
David Emanuel da Costa Santiago <[email protected]> wrote:
> If you want to replace all non printable characters you can do
> something like:
>
> ### START
>
> #Change the value to the maximum you want
> my %HEXCODES = map{$_ => sprintf("%03X", $_)} (0..128);
my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 );
>
> my $s="This is my string! \r\n the end";
>
> say "String before: $s";
>
> #Change the character class you want
> $s =~ s/([^[:print:]])/$HEXCODES{ord($1)}/g;
$s =~ s/([^[:print:]])/$HexCodes{$1}/g;
>
> say "String after: $s";
>
> ####END
__END__
--
Don't stop where the ink does.
Shawn H Corey
mailto:[email protected]
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/