Re: How remove newlines?
Sui Ming Louie wrote: > Try this: > > use strict; > use warnings; > my $tempstr = "abcdefghijklmnopqrstuvwxyz\r\n\r\n\r0123456789\n\n\r"; > $tempstr =~ s/(\r?\n)|(\r[^\n])|(\r$)//g; > print "[$tempstr]\n"; > > Output: > [abcdefghijklmnopqrstuvwxyz123456789] Your RE is overly complicated (this has already been posted as a solution) : s/[\r\n]+/ /g; use strict; use warnings; $_ = "abcdefghijklmnopqrstuvwxyz\r\n\r\n\r0123456789\n\n\rABCDEFGHIJKLMNOPQRSTUVWXYZ\n\n\r\n\r"; s/[\r\n]+/ /g; print "[$_]\n"; __END__ -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How remove newlines?
Previous reply had some "bugs". This one might be better. use strict; use warnings; my $tempstr = "abcdefghijklmnopqrstuvwxyz\r\n\r\n\r0123456789\n\n\rABCDEFGHIJKLMNOPQRSTUVW XYZ\n\n\r\n\r"; $tempstr =~ s/(\r?\n)|(\r)//g; print "[$tempstr]\n"; Output: [abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNO PQRSTUVWXYZ] Sui -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Martin Leese Sent: Friday, November 05, 2004 1:38 PM To: [EMAIL PROTECTED] Subject: How remove newlines? Hi, A nice easy one for a Friday afternoon. I have a variable containing text in which I wish to convert embedded newlines to spaces. And, I wish to do this in a way which is portable. I have come up with: $tempValue =~ s/\r\n/ /g; $tempValue =~ s/\n/ /g; I believe this pair of statements will work on both Windows and UNIX, and with text originating on both Windows and UNIX. I welcome improvements. Also, how do I accommodate Macs? Many thanks, Martin ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How remove newlines?
Try this: use strict; use warnings; my $tempstr = "abcdefghijklmnopqrstuvwxyz\r\n\r\n\r0123456789\n\n\r"; $tempstr =~ s/(\r?\n)|(\r[^\n])|(\r$)//g; print "[$tempstr]\n"; Output: [abcdefghijklmnopqrstuvwxyz123456789] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Martin Leese Sent: Friday, November 05, 2004 1:38 PM To: [EMAIL PROTECTED] Subject: How remove newlines? Hi, A nice easy one for a Friday afternoon. I have a variable containing text in which I wish to convert embedded newlines to spaces. And, I wish to do this in a way which is portable. I have come up with: $tempValue =~ s/\r\n/ /g; $tempValue =~ s/\n/ /g; I believe this pair of statements will work on both Windows and UNIX, and with text originating on both Windows and UNIX. I welcome improvements. Also, how do I accommodate Macs? Many thanks, Martin ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How remove newlines?
> -Original Message- > From: A B [mailto:[EMAIL PROTECTED] > Sent: Friday, November 05, 2004 2:10 PM > To: vega, james; Martin Leese > Cc: 'Glenn Linderman'; [EMAIL PROTECTED] > Subject: RE: How remove newlines? > > > $tempVale =~ s/\r?\n//g; What about Mac-formatted files which use just \r? > --- "vega, james" <[EMAIL PROTECTED]> wrote: > > > -Original Message- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED] On > > > Behalf Of Glenn Linderman > > > Sent: Friday, November 05, 2004 1:48 PM > > > To: Martin Leese > > > Cc: [EMAIL PROTECTED] > > > Subject: Re: How remove newlines? > > > > > > > > > On approximately 11/5/2004 10:38 AM, came the following > > > characters from > > > the keyboard of Martin Leese: > > > > Hi, > > > > > > > > A nice easy one for a Friday afternoon. > > > > > > > > I have a variable containing text in which I wish to convert > > > > embedded newlines to spaces. And, I wish to do this in a way > > > > which is portable. > > > > > > > > I have come up with: > > > > > > > > $tempValue =~ s/\r\n/ /g; > > > > $tempValue =~ s/\n/ /g; > > > > > > > > I believe this pair of statements will work on both Windows and > > > > UNIX, and with text originating on both Windows and UNIX. I > > > > welcome improvements. > > > > > > > > Also, how do I accommodate Macs? > > > > > > If a sequence of newlines can be converted to a single space, then > > > > > > $tempValue =~ s/[\r\n]*/ /g; > > > > That should be: > > > > $tempValue =~ s/[\r\n]+/ /g; > > > > Otherwise you'll end up putting spaces in more places than you like. > > > > > will do it. Otherwise, add > > > > > > $tempVale =~ s/\r/ /g; > > > > > > to your existing commands. (AFAIK -- I've never owned a Mac) > > > > > > -- > > > Glenn -- http://nevcal.com/ > > > === > > > Having identified a vast realm of ignorance, Wolfram is > > > saying that much of this realm lies forever outside the light > > > cone of human knowledge. > > >-- Michael Swaine, Dr Dobbs > > > Journal, Sept 2002 ___ > > > Perl-Win32-Users mailing list > > > [EMAIL PROTECTED] > > > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > > > ___ > > Perl-Win32-Users mailing list > > [EMAIL PROTECTED] > > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > > __ > > Post your free ad now! http://personals.yahoo.ca > ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How remove newlines?
$tempVale =~ s/\r?\n//g; --- "vega, james" <[EMAIL PROTECTED]> wrote: > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On > > Behalf Of Glenn Linderman > > Sent: Friday, November 05, 2004 1:48 PM > > To: Martin Leese > > Cc: [EMAIL PROTECTED] > > Subject: Re: How remove newlines? > > > > > > On approximately 11/5/2004 10:38 AM, came the following > > characters from > > the keyboard of Martin Leese: > > > Hi, > > > > > > A nice easy one for a Friday afternoon. > > > > > > I have a variable containing text in which I wish to > > > convert embedded newlines to spaces. And, I wish to > > > do this in a way which is portable. > > > > > > I have come up with: > > > > > > $tempValue =~ s/\r\n/ /g; > > > $tempValue =~ s/\n/ /g; > > > > > > I believe this pair of statements will work on both > > > Windows and UNIX, and with text originating on both > > > Windows and UNIX. I welcome improvements. > > > > > > Also, how do I accommodate Macs? > > > > If a sequence of newlines can be converted to a single space, then > > > > $tempValue =~ s/[\r\n]*/ /g; > > That should be: > > $tempValue =~ s/[\r\n]+/ /g; > > Otherwise you'll end up putting spaces in more places than you like. > > > will do it. Otherwise, add > > > > $tempVale =~ s/\r/ /g; > > > > to your existing commands. (AFAIK -- I've never owned a Mac) > > > > -- > > Glenn -- http://nevcal.com/ > > === > > Having identified a vast realm of ignorance, Wolfram is > > saying that much of this realm lies forever outside the light > > cone of human knowledge. > >-- Michael Swaine, Dr Dobbs > > Journal, Sept 2002 ___ > > Perl-Win32-Users mailing list > > [EMAIL PROTECTED] > > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > > ___ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > __ Post your free ad now! http://personals.yahoo.ca ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: How remove newlines?
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Glenn Linderman > Sent: Friday, November 05, 2004 1:48 PM > To: Martin Leese > Cc: [EMAIL PROTECTED] > Subject: Re: How remove newlines? > > > On approximately 11/5/2004 10:38 AM, came the following > characters from > the keyboard of Martin Leese: > > Hi, > > > > A nice easy one for a Friday afternoon. > > > > I have a variable containing text in which I wish to > > convert embedded newlines to spaces. And, I wish to > > do this in a way which is portable. > > > > I have come up with: > > > > $tempValue =~ s/\r\n/ /g; > > $tempValue =~ s/\n/ /g; > > > > I believe this pair of statements will work on both > > Windows and UNIX, and with text originating on both > > Windows and UNIX. I welcome improvements. > > > > Also, how do I accommodate Macs? > > If a sequence of newlines can be converted to a single space, then > > $tempValue =~ s/[\r\n]*/ /g; That should be: $tempValue =~ s/[\r\n]+/ /g; Otherwise you'll end up putting spaces in more places than you like. > will do it. Otherwise, add > > $tempVale =~ s/\r/ /g; > > to your existing commands. (AFAIK -- I've never owned a Mac) > > -- > Glenn -- http://nevcal.com/ > === > Having identified a vast realm of ignorance, Wolfram is > saying that much of this realm lies forever outside the light > cone of human knowledge. >-- Michael Swaine, Dr Dobbs > Journal, Sept 2002 ___ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
How remove newlines?
Hi, A nice easy one for a Friday afternoon. I have a variable containing text in which I wish to convert embedded newlines to spaces. And, I wish to do this in a way which is portable. I have come up with: $tempValue =~ s/\r\n/ /g; $tempValue =~ s/\n/ /g; I believe this pair of statements will work on both Windows and UNIX, and with text originating on both Windows and UNIX. I welcome improvements. Also, how do I accommodate Macs? Many thanks, Martin ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs