John W. Krahn wrote:
my ($prod, $flavor) = split /\s/, $ln, 2;
You probably should use ' ' instead of /\s/ as the first argument to
split:
my ($prod, $flavor) = split ' ', $ln, 2;
Ok, but why? Are they not the same?
No.
$ perl -le'
my $ln = " one two three four ";
print map " *$_* ", split /\s/, $ln, 2;
print map " *$_* ", split " ", $ln, 2;
'
** * one two three four *
*one* *two three four *
$ perl -le'
my $ln = "one two three four ";
print map " *$_* ", split /\s/, $ln, 2;
print map " *$_* ", split " ", $ln, 2;
'
*one* * two three four *
*one* *two three four *
/\s/ matches a single whitespace character, ' ' matches one or more whitespace
characters.
John
Thanks very much John and Chad. Excellent information and examples!
Thank you!
--
IBM: It's Been Malfunctioning
01:35:01 up 13 days, 22:26, 0 users, load average: 0.52, 0.55, 0.46
Linux Registered User #241685 http://counter.li.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/