I want to write a Perl 6 program that performs the same operation on an undetermined number of files, just like how you can use rm file1.txt file2.txt file3.txt
in Linux.
My code looks like this:
#!/usr/bin/env perl6
my @args = @*ARGS.perl;
for @args -> $arg {
say $arg
}
However, when I invoke it as ./loop_args.pl6 file1.txt file2.txt
I get the following output: ["file1.txt", "file2.txt"]
What am I doing wrong? I just want it to be an array.
For Perl6 the arguments array is @*ARGS
, this gives the code:
#! /usr/bin/env perl6
use v6;
for @*ARGS -> $arg
{
print("Arg $arg\n");
}
So you just need to remove the .perl
from your my @args = @*ARGS.perl;
line.
EDIT: Updated as per Ralphs's comments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With