At 02:50 PM 4/25/2001
> > Well, it's not obvious. To tell you honestly, I was initially
> > shocked that split didn't complain about the string, demanding a
> > pattern instead.
>
>"split ' '" is a pretty common idiom, though it still confuses me.
>I suppose it's hardcoded?
Yes. Check the bottom of my previous post. In perlfunc, split ' ' is
mentioned, because it is a special case, used to mimic awk's split
funcitonality.
> > If you'll look, you see that your
> >
> > split (".", $ARGV[0])
> >
> > becomes
> >
> > split (/./, $ARGV[0], 5)
> >
> > I don't know what the 5 is doing there ( I think it should be a 4,
> > because you are assigning the result of the split to 4 a list of
> > variables, but the compiler knows about many things that I don't.)
>
>I think i grok that one.
>Giving the numeric argument tells Perl when to stop splitting.
>If you ask for 4 things and don't give it that limiting factor, it
>decides looks at the context and figures out that it would be a waste
>of time to keep splitting, so leaves the 5th chunk unsplit since it's
>just going to be tossed anyway. Just guessing, though.
No guessing... it makes sense. Looking in the Camel (somewhat more verbose
than the docs) and reading *very* carefully, I think get it. It's not that
it leaves the 5th chunk unsplit, it's that Perl doesn't know how many
fields will result from the split until it actually does it. If you said
my ($one, $two, $three) = split /\./, $ARGV[0], 3;
and $ARGV[0] eq 'one.two.three.four', your result would be:
$one eq 'one'
$two eq 'two'
$three eq 'three.four'
With 4 as the split limit, the last item gets split up, $three end up eq
'three', and the 'four' gets dumped. It is to limit how far you split, but
it's set to one greater than what you really need so that you split enough
times to get what you really want, regardless of how many fields there
really are in the target string.
> > but you can see what happens. The string is made into a pattern, and
> > since that pattern is a single dot, it matches everything in the
> > string, so there's nothing to split on, so you get nothing back, and
> > as it is, your variables stay empty.
>
>I didn't read it that way.
>What I saw was that *any* character would qualify as a seperator, and
>so all it had to return was the empty space between chars.
>
>Paul
D'oh!
You're right. I guess it keeps hitting that initial null character at the
beginning of the string and not moving on? I dunno.
Thank you for your time,
Sean.