merlyn@iwarp.intel.com (Randal Schwartz) (03/07/90)
In article <1232@frankland-river.aaii.oz.au>, pem@frankland-river (Paul E. Maisano) writes: | Hey, I just thought of one way: ;-) | | grep( do { | ... # refer to array element as $_ | ... | }, | $array[EXPR] | ); Arrggh! grep() taken to the extreme!!! This is better supported as: for ($array[EXPR]) { ... ... ... } Same results exactly. If you assign into $_, the corresponding array element changes (right, Larry?). | Now if I could only name the variable something other than $_ ... Presto magico: for $something_other_than_dollar ($array[EXPR]) { ... ... ... } How's *that* for fast implementation? [inspired by a recent posting:] $_="kheauroes ,rJttParn lhc e";srand(1); while($a=length){$a=rand($a);print(substr($_,$a,1));substr($_,$a,1)="";} -- /=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!"=/
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (03/08/90)
In article <1990Mar7.055852.1192@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: : In article <1232@frankland-river.aaii.oz.au>, pem@frankland-river (Paul E. Maisano) writes: : | Hey, I just thought of one way: ;-) : | : | grep( do { : | ... # refer to array element as $_ : | ... : | }, : | $array[EXPR] : | ); : : Arrggh! grep() taken to the extreme!!! This is better supported as: : : for ($array[EXPR]) { : ... : ... : ... : } : : Same results exactly. If you assign into $_, the corresponding array : element changes (right, Larry?). Sorry, no. Only if you put the whole array in. The above gets translated internally to @_GEN_0 = ($array[EXPR]); for (@_GEN_0) { : | Now if I could only name the variable something other than $_ ... : : Presto magico: : : for $something_other_than_dollar ($array[EXPR]) { : ... : ... : ... : } : : How's *that* for fast implementation? Fast but still buggy. :-) But I'll admit it's real close to what he wants. : $_="kheauroes ,rJttParn lhc e";srand(1); : while($a=length){$a=rand($a);print(substr($_,$a,1));substr($_,$a,1)="";} Also non-portable to non-31-bit rand() machines. Larry
pem@frankland-river.aaii.oz.au (Paul E. Maisano) (03/08/90)
In article <1990Mar7.055852.1192@iwarp.intel.com>, merlyn@iwarp.intel.com (Randal Schwartz) writes: > Arrggh! grep() taken to the extreme!!! This is better supported as: > > for ($array[EXPR]) { > ... > ... > ... > } > > Same results exactly. If you assign into $_, the corresponding array > element changes (right, Larry?). Sorry, I had already tried that and it didn't work. I thought of the for loop before the grep but I think the manual says that the referencing through $_ only works for real arrays as opposed to lists. Anyway it doesn't work. It could be useful if it did work. I certainly don't see any harm in it. ------------------ Paul E. Maisano Australian Artificial Intelligence Institute 1 Grattan St. Carlton, Vic. 3053, Australia Ph: +613 663-7922 Fax: +613 663-7937 Email: pem@aaii.oz.au UUCP: {uunet,mcsun,ukc,nttlab}!munnari!aaii.oz.au!pem