Path: utzoo!attcan!uunet!snorkelwacker!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: split litteral vs reg.exp. Message-ID: <7479@jpl-devvax.JPL.NASA.GOV> Date: 20 Mar 90 18:46:03 GMT References: <237@carssdf.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 22 In article <237@carssdf.UUCP> usenet@carssdf.UUCP (John Watson) writes: : OK, so I'm a little dense, can one of you perl : 'hackers' tell me the difference between : split('_'); and split(/_/); When used on files : delimited by '_' like this: : First_Last_Address_City_State_Zip_etc...\n : Does it make any difference? Is one faster? : When would it make a difference? Semantically, there's no difference. The /_/ form is preferred because it will run faster. Saying '_' works because it's an expression, so it is evaluated at runtime. Perl does recognize the specific case of a single quoted string as something which won't change, so it doesn't recompile the regular expression each time. But it does miss out on the optimization that happens on /_/ (which will bypass the regular expression routines entirely, enabling a substantial speedup). The one runtime pattern ' ' is a special case. It actually gets translated to /\s+/, with the additional feature of skipping leading whitespace like awk does. Larry