Re: Mac Perl bug?

2006-07-19 Thread Paul McCann

Hi again,

Ugh: please ignore  my previous example, which split on the empty  
string by mistake (it's even evident in the script you quoted).  
Thwack...


Let me  try and pull this together: splitting on a string containing  
a single space is special in a do what you probably mean way: it's  
not the same as splitting on \s+, in that the former discards leading  
and trailing horizontal white space (ie, spaces or tabs).


So if we have

#!/usr/bin/perl
use warnings;
use strict;
my $string = \t12\t   3\t\t4\t;
print join(**, split( ,$string)),the end;
print \n;
print join(**,split(/\s+/,$string)),the end;


Produces the following output:
1**2**3**4the end
**1**2**3**4the end

In general: when using any regexp as the first argument the split  
function acts very much by the book.


Cheers,
Paul



Re: Mac Perl bug?

2006-07-19 Thread David Cantrell
On Wed, Jul 19, 2006 at 12:29:04AM +0200, ende wrote:

 Why?
 
 $a = 1  2 3;
   1  2 3
 split / /, $a;
   [1, , 2, 3]
 split  , $a;
   [1, 2, 3]

Splitting on / / is different from splitting on   because   is
magickal.  While this is mentioned in the docs for split(), it could
perhaps be written somewhat better.

-- 
David Cantrell | Enforcer, South London Linguistic Massive

Are you feeling bored? depressed? slowed down?  Evil Scientists may
be manipulating the speed of light in your vicinity.  Buy our patented
instructional video to find out how, and maybe YOU can stop THEM


Re: Mac Perl bug?

2006-07-18 Thread Paul McCann

Ende asked...


Why?

$a = 1  2 3;
1  2 3
split / /, $a;
[1, , 2, 3]
split  , $a;
[1, 2, 3]


Using a single space as the string on which to split triggers a  
special case: from perldoc -f split


   specifying a PATTERN of space (' ') will
   split on white space just as split with no  
arguments does.


Cheers,
Paul