Maybe the return value of String#split is wrong.
If I invoke split on an empty string, then it
results in an empty Array (which I think is odd).
''.split(/\n/) #=> []
I would have expected this to happen:
''.split(/\n/) #=> [""]
For instance JavaScript has a good split.
alert("".split(/\n/).length); // -> 1
Also Python has good split.
print "".split("\n"); # -> ['']
However Perl has a bad split.
$size = split(/\n/, "");
print "size is $size"; # -> 0
···
--
Simon Strandgaard
Perl's split() works as you described above. You just need to call it in "list context":
@arr = split /\n/, "";
# ...
James
···
On Dec 6, 2004, at 1:20 PM, Simon Strandgaard wrote:
However Perl has a bad split.
$size = split(/\n/, "");
print "size is $size"; # -> 0
Trans1
(Trans)
4
James Edward Gray II wrote:
> However Perl has a bad split.
>
> $size = split(/\n/, "");
> print "size is $size"; # -> 0
Perl's split() works as you described above. You just need to call
it
in "list context":
@arr = split /\n/, "";
# ...
Try
@arr = split /\n/, -1;
Which I think should be defualt behavior.
T.
···
On Dec 6, 2004, at 1:20 PM, Simon Strandgaard wrote: