A little refinement.

On Tue, 6 Sep 2016 21:04:04 +0200
David Emanuel da Costa Santiago <deman...@gmail.com> 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:shawnhco...@nili.ca

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to