Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
On Tue, 6 Sep 2016 22:08:40 +0200 David Emanuel da Costa Santiago wrote: > > > Thanks :-) > > A little bug: > > > my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 ); > my %HexCodes = map { chr($_) => sprintf '%02X', $_ } ( 0 .. 128 ); > > > > Oops. :) -- Don't stop wher

Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
On Tue, 6 Sep 2016 17:01:52 -0400 Uri Guttman wrote: > On 09/06/2016 04:42 PM, X Dungeness wrote: > > It's kinda hard to see but I included the /x switch because > > I inserted blanks on the pattern as well as the replacement > > side. Without /x, the match will fail. > > > > $str =~ s{ ([^[:pri

Re: Remove Newlines from String

2016-09-06 Thread Uri Guttman
On 09/06/2016 04:42 PM, X Dungeness wrote: It's kinda hard to see but I included the /x switch because I inserted blanks on the pattern as well as the replacement side. Without /x, the match will fail. $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; ^

Re: Remove Newlines from String

2016-09-06 Thread X Dungeness
It's kinda hard to see but I included the /x switch because I inserted blanks on the pattern as well as the replacement side. Without /x, the match will fail. $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; ^ ^ On Tue, Sep 6, 2016 at 1:06 PM, Ur

Re: Remove Newlines from String

2016-09-06 Thread David Emanuel da Costa Santiago
Thanks :-) A little bug: > my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 ); my %HexCodes = map { chr($_) => sprintf '%02X', $_ } ( 0 .. 128 ); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.p

Re: Remove Newlines from String

2016-09-06 Thread Uri Guttman
On 09/06/2016 03:59 PM, X Dungeness wrote: $str = "ab\rcd\nef\ngh\fij"; $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; > ab(0XD)cd(0XA)ef(0XA)gh(0XC)ij that is a nice use of /e (don't think you need /x when you already have /e as code can handle blanks. but the # com

Re: Remove Newlines from String

2016-09-06 Thread X Dungeness
$str = "ab\rcd\nef\ngh\fij"; $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; > ab(0XD)cd(0XA)ef(0XA)gh(0XC)ij On Tue, Sep 6, 2016 at 9:11 AM, Matt wrote: > I am receiving log entries as a string and then writing them to a file > with the date tacked on beginning. Probl

Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
A little refinement. On Tue, 6 Sep 2016 21:04:04 +0200 David Emanuel da Costa Santiago 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);

Re: Remove Newlines from String

2016-09-06 Thread David Emanuel da Costa Santiago
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 en

Re: Remove Newlines from String

2016-09-06 Thread Kenneth Wolcott
On Tue, Sep 6, 2016 at 9:11 AM, Matt 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 wa

Remove Newlines from String

2016-09-06 Thread Matt
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 or somet