Path: utzoo!attcan!uunet!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Using 'split' with multi character expressions Message-ID: <1990May26.000037.4846@iwarp.intel.com> Date: 26 May 90 00:00:37 GMT References: <1933@pyrltd.UUCP> <8203@jpl-devvax.JPL.NASA.GOV> <9423@pt.cs.cmu.edu> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 40 In-Reply-To: mleone@f.gp.cs.cmu.edu (Mark Leone) In article <9423@pt.cs.cmu.edu>, mleone@f.gp (Mark Leone) writes: | | On a related note, why doesn't split allow a case-insensitive pattern? | I.e., split(/$word/i, $string). It seems like all the other pattern | operations support case-insensitivity! | | Is there some other good way to do this when $word and $string are not | known at compile-time? Well, as a bit of a hack, I could suggest: sub isplit { # &isplit(word,string) => array local($word,$_) = @_; local(@ind,@result,$start,$end); @ind = (0); s#$word#push(ind,length($`),length($`.$&)),$&#ieg; push(ind,length); # @ind now has pairs of indicies (0-origin) into $_ # that bound the non-$word items; convert into result: while (@ind) { $start = shift(ind); $end = shift(ind); push(result,substr($_,$start+$[,$end-$start)); } @result; } print join(":",&isplit("z","foo z bar Z bletch")),"\n"; print join(":",&isplit("x*y","foo xy bar xxxy bletch XxXxY bug")),"\n"; Yup, doesn't handle the equiv of split(/(a)/i, $string). Anyone care to try that? This is all I could do in the 20 minutes I had to play with this today. print &isplit("z","JzuZsztZ zaZnzoZtzhZezrZ zPZezrZlz ZhzaZczkZezrZ,"); -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/