On Thu, Dec 28, 2006 at 08:51:26AM +0000, Igor Sutton wrote: > 2006/12/28, Chad Perrin <[EMAIL PROTECTED]>: > > > >That makes sense, considering I just checked the tutorials at PerlMonks > >and discovered that, according to split(), ' ' and /\s+/ are exactly the > >same. Frankly, I find that a bit surprising. > > > It is not the same: > > [EMAIL PROTECTED] ~]$ perl -MData::Dumper -le "@foo = split /\s+/, qq( one two > three\t\n four ); print Dumper [EMAIL PROTECTED];" > $VAR1 = [ > '', > 'one', > 'two', > 'three', > 'four' > ]; > > [EMAIL PROTECTED] ~]$ perl -MData::Dumper -le "@foo = split ' ', qq( one two > three\t\n four ); print Dumper [EMAIL PROTECTED];" > $VAR1 = [ > 'one', > 'two', > 'three', > 'four' > ]; > > If you use /\s+/ and your string has trailing spaces at beginning, it will > create an empty string element on array, while using ' ' it won't.
It's still rather surprising. Also, that tutorial I read could stand to be written a bit more clearly. Why doesn't perldoc -f split say anything about that? Never mind, I guess that's a rhetorical question. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "There comes a time in the history of any project when it becomes necessary to shoot the engineers and begin production." - MacUser, November 1990 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/