Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Is there a non-empty error quine in perl?

by ambrus (Abbot)
on Mar 09, 2014 at 00:59 UTC ( [id://1077569]=obfuscated: print w/replies, xml ) Need Help??

Can you give a non-empty error quine for perl? By an error quine, I mean a perl script that, when ran perl, prints exactly the same bytes to its standard error as its source code and nothing on its stdout. The printout shall be an error message coming from the perl core (or maybe a core module), not eg. something explicitly printed with a die or print statement in the source code. The program shall be ran by redirecting it to the stdin of perl, invoked without any switches.

If there is such an error quine, please give one, preferably an elegant one which doesn't seem like cheating. Please tell what version of perl the script works with.

As an example that doesn't work, take the following script:

Number found where operator expected at - line 1, near "line 1" (Do you need to predeclare line?)
If you run this with perl 5.16.3, you get the same error message as the source, but then get other error messages too, so this isn't an error quine.

Update: asked for perl version.

Update: ais523 says these are called “Kimian quines”

Replies are listed 'Best First'.
Re: Is there a non-empty error quine in perl?
by kcott (Archbishop) on Mar 09, 2014 at 22:43 UTC

    G'day ambrus,

    I believe this is an example of what you're after:

    CORE:: is not a keyword at -e line 1.

    I checked like this which I think follows all your rules (but do advise if that's not the case).

    $ perl -e 'CORE:: is not a keyword at -e line 1. ' 1> /dev/null CORE:: is not a keyword at -e line 1. $

    [Note: the newline after "line 1." was to match the newline output to stderr.]

    Perl version: v5.18.1 built for darwin-thread-multi-2level

    -- Ken

      Nice trick! Congratulations. And it still works if I modify it to run from the stdin from perl.

      CORE:: is not a keyword at - line 1.
      This works with older versions of perl too, including perl 5.12.3.

        And on:

        $ /bin/perl -v This is perl, v5.8.8 built for msys

        --MidLifeXis

        and on
        # perl -e 'print "$^V\n"' v5.10.1
Re: Is there a non-empty error quine in perl?
by hdb (Monsignor) on Mar 09, 2014 at 17:58 UTC

    Is there a list of all possible error messages somewhere? I started to write this quine tester but now I have no idea how to feed it.

    use strict; use warnings; use Sysadm::Install qw(tap); my $quine = 'Number found where operator expected at - line 1, near "l +ine 1" (Do you need to predeclare line?)'; my($stdout, $stderr, $rc) = tap "perl", "-e", $quine; print "stdout=$stdout\n", "stderr=$stderr\n", "rc=$rc\n"; if( $stdout eq '' and $stderr eq $quine ) { print "Found error quine!\n"; }

    UPDATE: Forgot to thank saintmike for Re: Capturing both STDOUT, STDERR and exit status.

      perldiag has them all, but you might need to fill in the placeholders with something tricky like __DATA__ maybe.

      In addition to what Corion says about placeholders, be aware that quoting, not shown in perldiag, may be added. For instance, that documentation shows this error message:

      Can't find string terminator %s anywhere before EOF

      Consider how that message is subtly changed by adding single quotes (around %s) in the first example below and double quotes in the second example.

      $ cat pm_error_quine Can't find string terminator " anywhere before EOF at pm_error_quine l +ine 1. $ perl pm_error_quine 1> /dev/null Can't find string terminator '"' anywhere before EOF at pm_error_quine + line 1. $
      $ cat pm_error_quine Can't find string terminator ` anywhere before EOF at pm_error_quine l +ine 1. $ perl pm_error_quine 1> /dev/null Can't find string terminator "`" anywhere before EOF at pm_error_quine + line 1. $

      -- Ken

Re: Is there a non-empty error quine in perl?
by ambrus (Abbot) on Mar 10, 2014 at 06:50 UTC
Re: Is there a non-empty error quine in perl?
by ambrus (Abbot) on Apr 21, 2017 at 11:13 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://1077569]
Approved by davido
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found