Re: HoA building
- From: perrin@xxxxxxxxxxxx (Chad Perrin)
- Date: Thu, 28 Dec 2006 00:23:47 -0700
On Wed, Dec 27, 2006 at 10:58:40PM -0700, Chad Perrin wrote:
On Wed, Dec 27, 2006 at 07:42:59PM -0500, M. Lewis wrote:
John W. Krahn wrote:
M. Lewis wrote:
while (my $ln = <DATA>){
chomp $ln;
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, they're not. ' ' is a literal space. /\s/ matches any whitespace.
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
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"The measure on a man's real character is what he would do
if he knew he would never be found out." - Thomas McCauley
.
- Follow-Ups:
- Re: HoA building
- From: Igor Sutton
- Re: HoA building
- From: M. Lewis
- 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
- HoA building
- Prev by Date: Re: HoA building
- Next by Date: Strange problem with glob <>
- Previous by thread: Re: HoA building
- Next by thread: Re: HoA building
- Index(es):
Relevant Pages
|
|