Narcissist: Difference between revisions

→‎{{header|Perl 6}}: avoiding single quotes so we don't need shell escape + using actual proposal in comment
m (→‎{{header|Perl 6}}: A note about non-cheating.)
(→‎{{header|Perl 6}}: avoiding single quotes so we don't need shell escape + using actual proposal in comment)
Line 137:
=={{header|Perl 6}}==
 
For the narcissist to work you must be very careful with whitespace. The presentedfollowing version works if it is storedgiven asto astandard fileinput ofas exactly one line terminated by a newline character. (As this is a non-cheating narcissist, you don't <em>have</em> to put it in a file. With enough shell quoting-fu you could even pass it to "perl6 -e".)
 
Note how the code takes advantage of Perl 6's ability to nest quoting delimiters.
 
<lang perl6>eval my $self = q{say slurp() eq 'q[eval my $self = q{']~$self~'q[}']~10.chr ?? 'q{Beautiful!'} !! 'q{Not my type.'}}</lang>
</lang>
 
{{out}}
<pre>$ narcissist='eval my $self = q{say slurp() eq q[eval my $self = q{]~$self~q[}]~10.chr ?? q{Beautiful!} !! q{Not my type.}}'
<pre>$ rakudoperl6 -e "$narcissist.pl" <<<"$narcissist.pl "
Beautiful!
$ rakudoperl6 -e "$narcissist.pl" <any-other-input.pl<<"$narcissist # a comment ruining it all"
Not my type.
</pre>
1,934

edits