This is a poetic quine (or quine-maker) in perl5.

  open myself, $0 and print <myself>;

The same thing in perl6 would be:

  my $self = open $*PROGRAM_NAME; for =$self { say }


  my $self = open $*PROGRAM_NAME; say for =$self;


  my $self = slurp $*PROGRAM_NAME; print $self;

or even

  $*{ print };

The last example must not be


You can check it out by running the code below;


Will print:


This is because print() (and say()) expects list context and slurp() passes an array of chomped strings. When it comes to autoboxing, the context-sensitivity of builtins may bite you like this.

With that understood, I would welcome if we have a version of slurp() which unconditionally returns a scalar. Say swallow()? Of course it is as easy to implement as the following;

  sub swallow($file){ my $content = slurp $file; return $content };

But like say(), I would love to have something like that as a builtin.

Or am I getting too much ruby recently?

Dan the Perl6 Addict

Reply via email to