Skip to content

Instantly share code, notes, and snippets.

@nd3i
Created May 2, 2016 22:36
Show Gist options
  • Save nd3i/03750ed3a67a2c0368773c127d165e6a to your computer and use it in GitHub Desktop.
Save nd3i/03750ed3a67a2c0368773c127d165e6a to your computer and use it in GitHub Desktop.
use v6;
sub MAIN (:$sep = "\t", :$min = 0) {
my ($lines, $words, $chars) = 0 xx 3;
for lines() -> $l {
$lines += 1;
$chars += $l.chars + 1;
$words += $l.subst(/<-alpha -space>/,'',:g).words.grep(*.chars >= $min);
}
say ($lines, $words, $chars).join($sep);
}
@nd3i
Copy link
Author

nd3i commented May 2, 2016

Here's the complete message:

$ perl6 -v
This is Rakudo version 2016.04-33-gf05c77b built on MoarVM version 2016.04
implementing Perl 6.c.

$ perl6 wc.p6 --min=5 </tmp/words 
Earlier failure:
 (HANDLED) Unable to open file '--min=5'
  in sub MAIN at wc.p6 line 7
  in block <unit> at wc.p6 line 3

Final error:
 Type check failed in binding $iter; expected Iterator but got Failure (Failure.new(exception...)
  in sub MAIN at wc.p6 line 7
  in block <unit> at wc.p6 line 3

@smls
Copy link

smls commented May 2, 2016

Try this:

sub MAIN (*@files, :$sep = "\t", :$min = 0) {
    @*ARGS = @files;

    # ....rest as before
}

Or more concisely, at the risk of confusing readers:

sub MAIN (*@*ARGS, :$sep = "\t", :$min = 0) {
    # ....rest as before
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment