>-----Original Message----- >From: Mr. Shawn H. Corey [mailto:[EMAIL PROTECTED] >Sent: Wednesday, April 26, 2006 1:32 PM >To: Rance Hall >Cc: beginners@perl.org >Subject: Re: problem with whitespace not splitting on split. > >On Wed, 2006-26-04 at 15:22 -0500, Rance Hall wrote: >> I'm working on a new perl script thats giving me fits. >> >> Ive never quite seen anything like this. >> >> here is the command that is not giving me the results I want. >> >> @domain = split(' ',$domainlist); >> >> what should have happened was that if there was any whitespace in the >> file (including new lines, and such) thats where the split would have >> occurred > > @domain = split /\s+/, $domainlist; > >It's not splitting on whitespace since you are telling it to split on a >single space character (ASCII 0x20).
The confusion comes from the poor wording of the perldoc. "As a special case, specifying a PATTERN of space (' ') will split on white space just as "split" with no arguments does. Thus, "split(' ')" can be used to emulate awk's default behavior, whereas "split(/ /)" will give you as many null initial fields as there are leading spaces. A "split" on "/\s+/" is like a "split(' ')" except that any leading whitespace produces a null first field. A "split" with no arguments really does a "split(' ', $_)" internally." It doesn't make it clear whether it's really talking about whitespace (as in \w) or just spaces. This is why I avoid using "magic" whenever possible. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>