Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Randal's one-liners Message-ID: <7349@jpl-devvax.JPL.NASA.GOV> Date: 8 Mar 90 23:48:18 GMT References: <15214@bfmny0.UU.NET> <15216@bfmny0.UU.NET> <7250@jpl-devvax.JPL.NASA.GOV> <7282@jpl-devvax.JPL.NASA.GOV> <1990Mar6.110732.11660@kaukau.comp.vuw.ac.nz> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 28 In article <1990Mar6.110732.11660@kaukau.comp.vuw.ac.nz> ajv@comp.vuw.ac.nz (Andrew Vignaux) writes: : I'm afraid I can't get my submission down to 1 line (excluding data) :-( : Can anyone help? : : @l = split (/(..)/,'1a7r4J1n0a7e7c1o8n248o1t4u8v4s7.207l27547a7n7g1h'. : '0 511e3h7.8i564t3a6P1r7p8c8e6e3c3k7e3e533r7r286r6l4 6 1 8,7l7 3,'); : srand; $_=3*int(rand(2))+2; /^$_/; : foreach (split(//,&g)) {/^$_/;print &g;} print "\n"; : sub g {join('',grep(s/^.//,grep(//,@l)));} You want it in one line? Does it have to fit in 80 columns? :-) I really liked your "holographic" approach. I had to stare at it quite some time for things to resolve. I thought I was going crazy when it printed out something different when I ran it on a different machine. : The interesting bit is the "grep(//,@l)". Is this a "feature" ;-) : Can anyone exploit it in a real script? Yes, it's a feature. Any null pattern (except in a split) just refers back to the last real pattern match, ala ed and sed. I imagine this would be one mechanism for getting around the problem mentioned earlier of having run-time patterns that you don't want to recompile every iteration of a grep, but that you want to change occasionally, which rules out /$pat/o (except in an eval). Larry