Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Why isn't this a quine?

by mchampag (Acolyte)
on Aug 01, 2009 at 23:39 UTC ( [id://785143]=perlquestion: print w/replies, xml ) Need Help??

mchampag has asked for the wisdom of the Perl Monks concerning the following question:

I apologize for posing a silly question, but does the following qualify as a quine, and if not, why?
#!/usr/bin/perl system "cat $0";
Respectfully,
Matt

Replies are listed 'Best First'.
Re: Why isn't this a quine?
by plobsing (Friar) on Aug 01, 2009 at 23:54 UTC

    It's not a true quine. A true quine generates it's own source. This only finds the file that contains the source and prints it.

    It also has a race condition: if I replace the file shortly after you've run it, it will output whatever is in the new file and not the source code.

      Now that's the sort of response I was expecting. So it's not enough to simply print out its code listing; a quine must also generate itself. Very koan-like.

      Thank you!
      A true quine generates it's own source.
      What does it mean to ‘generate’ source? Unless you mean something subjective like “uses clever or tricky-to-understand mechanisms”, it seems to me that the OP's proposed quine ‘generates’ its source using a call to system, which makes a further call to cat.
Re: Why isn't this a quine?
by GrandFather (Saint) on Aug 02, 2009 at 00:13 UTC

    Perl is not one of the worst languages for generating a quine:

    seek DATA, 0, 0; print <DATA> __DATA__

    Prints:

    seek DATA, 0, 0; print <DATA> __DATA__

    True laziness is hard work

      might as well make it psuedo-palandromy

      hossman@coaster:~$ cat monk.pl seek DATA, 0, 0; print <DATA> __DATA__ print <DATA> seek DATA, 0, 0; hossman@coaster:~$ perl monk.pl seek DATA, 0, 0; print <DATA> __DATA__ print <DATA> seek DATA, 0, 0;
Re: Why isn't this a quine?
by eyepopslikeamosquito (Archbishop) on Aug 02, 2009 at 03:56 UTC
Re: Why isn't this a quine?
by dave_the_m (Monsignor) on Aug 02, 2009 at 12:06 UTC
    s zzs vvxv and s ZVZchr 122Zie and s ZVZchr 122Zie and s ZVZchr 122Zie and s SxSlcfirstSe and s YZZxZYvvxvYi and print z and s ZVZchr 122Zie and s ZVZchr 122Zie and s ZVZchr 122Zie and s SxSlcfirstSe and s YZZxZYvvxvYi and print
      That's adorable. I thought at first that it was Befunge or some variant—then I wondered about what purpose a command like s would serve in a directional language—then enlightenment dawned (though it took me a while to find the third ‘z’).
Re: Why isn't this a quine?
by Anonymous Monk on Aug 01, 2009 at 23:46 UTC
      Thank you for your response! I thought it fitted the definition, but every quine I've ever seen seems to be very difficult to understand. As this one is trivially simple, it seems like it should maybe be disqualified.

      -Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://785143]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found