Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!hansm From: hansm@cs.kun.nl (Hans Mulder) Newsgroups: comp.lang.perl Subject: Re: Self-reproducing program Message-ID: <2901@wn1.sci.kun.nl> Date: 27 Mar 91 20:04:51 GMT References: <1991Mar26.210348.12286@uvaarpa.Virginia.EDU> Sender: root@sci.kun.nl Organization: University of Nijmegen, The Netherlands Lines: 43 In article <1991Mar26.210348.12286@uvaarpa.Virginia.EDU> worley@compass.com writes: >I don't know if this has been hashed over before, but: What is the >shortest self-reproducing Perl program? (Well, the null file is, but >what is the shortest non-trivial program?) > >The best I've been able to do is: > >print @a=,@a >__END__ >print @a=,@a >__END__ Last time we had this debate, several shorter scripts were posted: The first example is a 3-liner; the third line being empty: print<<''x 2,$/ print<<''x 2,$/ The ohter four examples do not contain newlines; according to wc(1), they are 0-liners: This one assumes ascii, to the extent that ord("'")==39: $s='$s=%c%s%c;printf$s,39,$s,39';printf$s,39,$s,39 This one does not unduly assume anything: $_=q $_=qx;s/x/$"$_$"/;print ;s/x/$"$_$"/;print The whitespace in this one must be tabs: $_=q print"\$_=q\t$_\t;eval" ;eval This one again uses "\47" eq "'": $_='print"\$_=\47$_\47;eval"';eval Have a nice day, Hans Mulder hansm@cs.kun.nl