Hi Chad,
2006/12/28, Chad Perrin <[EMAIL PROTECTED]>:
[snip]
Actually, on second thought, I seem to recall that ' ' has a meaning in
split() beyond a literal space. Unfortunately, I don't recall exactly
what that is. I've tried looking it up using perldoc -f split and in
several books I have here, and I've tried testing it in simple Perl
scripts. The end result is that I've got nothin' -- except that it so
far seems to be acting just like /\s/.
I'd appreciate it if someone on this list would remind me about the
differences. Both ' ' and /\s/ seem to be matching multiple whitespace
characters when used with split() with no differences, including
matching spaces, tabs, and newline characters.
Example:
$ perl -le "@foo = split ' ', qq( one two three\t\n four ); print
@foo;"
onetwothreefour
$ perl -le "@foo = split /\s/, qq( one two three\t\n four ); print
@foo;"
onetwothreefour
Actually, ' ' on split has a "magical". You would see it if you used
Data::Dumper to check the array split returned:
[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'
];
From "perldoc -f split":
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
behav-
ior, 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.
HTH
--
Igor Sutton Lopes <[EMAIL PROTECTED]>