Hi!
You can use "chomp" to remove the $/ from the end of the line.
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 $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;
say "String after: $s";
####END
Regards,
David Santiago
On Tue, 6 Sep 2016 11:11:35 -0500
Matt <[email protected]> wrote:
> I am receiving log entries as a string and then writing them to a file
> with the date tacked on beginning. Problem is that sometimes the
> string I receive contains \n and it makes parsing the file with grep
> more difficult. Looking for a simple way to replace all \n in the
> string with text <CR> or something of that sort.
>
> It might be even better yet to replace all characters that are not
> directly printable with there HEX equivalent since I only need
> readable text log info on one line. Is there an easy way to do that?
>
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/