Re: HoA building
- From: cajun@xxxxxxxxxxxx (M. Lewis)
- Date: Thu, 28 Dec 2006 03:31:36 -0500
Chad Perrin wrote:
John W. Krahn wrote:No, they're not. ' ' is a literal space. /\s/ matches any whitespace.M. Lewis wrote:Ok, but why? Are they not the same?while (my $ln = <DATA>){You probably should use ' ' instead of /\s/ as the first argument to split:
chomp $ln;
my ($prod, $flavor) = split /\s/, $ln, 2;
my ($prod, $flavor) = split ' ', $ln, 2;
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
Chad, I've been experimenting with this a bit since your posting. Maybe this will help: (I'm trying to understand the diff too)
perl -le'
my $ln = "one two three four ";
print map " |$_| ", split /\s/, $ln;
print map " |$_| ", split " ", $ln;
'
|one| || |two| || |three| || |four|
|one| |two| |three| |four|
perl -le'
my $ln = "one two three four ";
print map " |$_| ", split /\s+/, $ln;
print map " |$_| ", split " ", $ln;
'
|one| |two| |three| |four|
|one| |two| |three| |four|
--
Swap read error. You lose your mind.
03:25:01 up 14 days, 16 min, 0 users, load average: 0.36, 0.33, 0.38
Linux Registered User #241685 http://counter.li.org
.
- Follow-Ups:
- Re: HoA building
- From: Chad Perrin
- Re: HoA building
- References:
- HoA building
- From: "M. Lewis"
- Re: HoA building
- From: John W. Krahn
- Re: HoA building
- From: "M. Lewis"
- Re: HoA building
- From: Chad Perrin
- Re: HoA building
- From: Chad Perrin
- HoA building
- Prev by Date: Re: click_button gives error on a existing button
- Next by Date: Re: Strange problem with glob <>
- Previous by thread: Re: HoA building
- Next by thread: Re: HoA building
- Index(es):