Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 6 iterate through command line arguments

Tags:

raku

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.

like image 893
Taylor Lee Avatar asked Nov 13 '18 01:11

Taylor Lee


1 Answers

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

like image 65
Kingsley Avatar answered Oct 03 '22 03:10

Kingsley