he expected @foo to have 6 elements. According to the perl documentation:$_="|" x 5; @foo = split /\|/,$_; print scalar @foo; # prints 0
Splits a string into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted.So if there are no fields to be parsed by the split, then it treats them all as empty trailing fields. My coworker said, "I think of them as empty leading fields!" The solution is to split as such:
to set an arbitrarily large limit and force split to treat them as empty leading fields, but that doesn't seem like the right (read: perl) way for things to happen. I'd expect perl to gracefully treat complete pseudo-emptiness as something, rather than nothing.@foo = split /\|/,$_,-1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: splitting nothing?
by etcshadow (Priest) on Jul 13, 2004 at 22:18 UTC | |
|
Re: splitting nothing?
by Zaxo (Archbishop) on Jul 13, 2004 at 21:37 UTC | |
|
Re: splitting nothing?
by ysth (Canon) on Jul 13, 2004 at 21:57 UTC | |
by bageler (Hermit) on Jul 13, 2004 at 23:53 UTC | |
by ysth (Canon) on Jul 14, 2004 at 00:04 UTC | |
by bageler (Hermit) on Jul 14, 2004 at 15:59 UTC | |
by ihb (Deacon) on Jul 16, 2004 at 21:44 UTC | |
by ysth (Canon) on Jul 17, 2004 at 01:44 UTC | |
by ihb (Deacon) on Jul 17, 2004 at 19:49 UTC | |
by ysth (Canon) on Jul 18, 2004 at 22:19 UTC | |
|