Alternative to Perl's <> in Raku?

The functionality you're looking for largely exists. This script:

my $x = get();
say "First: $x";
for lines() {
    .say
}

Given these inputs files:

$ cat foo
foo line 1
foo line 2
$ cat bar
bar line 1
bar line 2

Will, when invoked as:

raku script.p6 foo bar

Produce the output:

First: foo line 1
foo line 2
bar line 1
bar line 2

It will also take output from $*IN if there aren't files. The only thing that doesn't exist is a single replacement for <>, since that would depend on wantarray-like functionality, which is incompatible with multiple dispatch (and Raku considers multiple dispatch is far more useful).

The zero-arg candidates for get and lines are implemented in terms of $*ARGFILES, a file handle that provides the functionality of taking the files from the argument list or from $*IN - meaning one can pass it to any code that expects a file handle.

Tags:

Migration

Raku