Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!dixie.com!eeh From: eeh@Dixie.Com (Ed Howland) Newsgroups: comp.lang.perl Subject: Re: Shortest Perl and Awk programs Message-ID: <9267@rsiatl.Dixie.Com> Date: 6 Apr 91 02:52:12 GMT References: <9004@rsiatl.Dixie.Com> <1991Apr5.004600.17363@NCoast.ORG> Organization: Dixie Communications Services Lines: 41 allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/AA) writes: >As quoted from <9004@rsiatl.Dixie.Com> by eeh@Dixie.Com (Ed Howland): >+--------------- >| !0 >| Is there anything shorter? Why does'nt just '1' (or any non-zero value) work? >+--------------- >It probably matches the line number, so a given positive number N would match >only on line N. (??? I have never understood all of awk completely; the >documentation for standard awk seems to leave a lot to be desired. The new >awk and GNU awk may well be different there --- new awk has a book, at least.) Several people responded that the reason was since everything in awk was treated (by default) as a string, a 1 (or other non-zero numeric) would not match the current line. By using the negate, awk interprets the next token as a number, thereby correctly evaluating the expression to true, which causes the default action (i.e. copy input to output). Interestingly, some newer implementations of awk (SYSV3) seem to think this is a syntax error (and give the famous 'bailing out...' msg.) So I haven't been able to experiment further, (need to get back to SYSV2, I guess). Makes me wonder what the shortest default prog is for these other implementations. But you may be right as well. This is helping me understand the internal workings of programs like perl and awk. >"perl -pe ''" is the shortest, but may not be fair because it uses command >line arguments to "imply" a script. >++Brandon Yes I got several answers that said -p was the shortest, I agree it might not be the same comparison. BTW does anybody know if gawk (GNU Awk) executes this? Ed. -- Ed Howland Internet: eeh@dixie.com uucp: ...{uunet,emory}!rsiatl!eeh "I am expressly forbidden to offer any kind of warranty. This covers ideas, thoughts, opinions, or just plain gibberish. They are only offered 'As is'."