in reply to Re: Substitution
in thread replacing one or more newlines with commas

Hi,

The real problem that i'm having is that when someone enters text and then hits return twice, i get an empty value in the array and that's what i'm really trying to get rid off.

For example, If i enter the following text:

text1 text2 text3 text4
I will get that one empty value in the array and i need to delete it. Is there a way to search the array for any empty values and remove them?

Thanx,
Kiko

Edit: chipmunk 2001-05-31

Replies are listed 'Best First'.
Re: Re: Re: Substitution
by lestrrat (Deacon) on May 31, 2001 at 23:55 UTC

    then split( /\n+/, $text ) is your friend

    On a second thought, can these parameters contain \r\n? in that case, split( /(?:\r?\n)+/, $text ) should do...

      Generally, (at least in theory, under Perl 5.6, &c.) "\n" means "whatever makes a new line," and not necessarily "an ASCII LF character." "\n" could very well translate to \012 (Unix -- ASCII's "linefeed" char), \015 (MacOS < 10 -- ASCII's "carriage return" char), or \015\012 (MS-DOS/Windows -- CRLF)...

      Of course, this relies on a lot of magic, like binmode disciplines, all working as they should, so it's quite possible that some "\r\n" sequences could slip in despite it all... :-) The joys of relying on the cutting edge.


      #!/Applications/Utilities/perl -T use strict; use warnings; use utf8; no bytes; require v5.6.5;