develooper Front page | perl.beginners | Postings from September 2016

Re: Remove Newlines from String

Thread Previous
From:
Kenneth Wolcott
Date:
September 6, 2016 16:46
Subject:
Re: Remove Newlines from String
Message ID:
CADex0xwgd3H3jJHWcJHTGDNWLoFYuW0afgpecxKxftc+V-tjfA@mail.gmail.com
On Tue, Sep 6, 2016 at 9:11 AM, Matt <matt.mailinglists@gmail.com> 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?

Perhaps you might want to look at "chomp"?
http://perldoc.perl.org/functions/chomp.html

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About