From: Dossy Date: 2002-07-10T23:09:24+09:00 Subject: Re: String#split converts string args to regexes -- ? On 2002.07.10, David Alan Black wrote: > Hi -- > > On Wed, 10 Jul 2002, Yukihiro Matsumoto wrote: > > > In message "Re: String#split converts string args to regexes -- ?" > > on 02/07/10, David Alan Black writes: > > > > |> (c) prohibit string pattern longer than 1. > > | > > |Why the one-character exception? I'm still not getting that. > > > > AWKish behavior is used too much to omit, and useful as well. > > I'm probably OT here, but I'm very curious about this.... What is it > in AWK that behaves this way (one-char string as string, multi-char > converted to regex)? I think there's some piece of the puzzle I'm not > seeing. (But I still vote for b/d :-) awk being typeless can't distinguish between a regex vs. a string, so a very common split on | in pipe-delimited files would be denoted as: split($0, fields, "|") ... to have to escape | as \| was probably a nuisance. Generally, when you're splitting on a single character it's not meant to be a regular expression. When you're splitting on more than a single character, the odds are it's a pattern -- if it's not, simply escape the regex metachars ... This "odd" behavior comes from the most useful case, not the most logical or predictable case. Perhaps the idea is "inconvenience the least amount of uses of split() at the cost of some edge-case confusion." I do agree, though, that in a language like Ruby where you can differentiate between a String and a Regex that this "magic" is unnecessary. -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)