Is there an idiomatic way to pass a Regex from the command line to a Raku program. The following code accomplishes what I’m trying to do but it has a few issues (see below).
#!/bin/raku
use MONKEY-TYPING;
augment class Str {
method Regex {
my $tmp = self.Str;
return rx/ <$tmp> /;
}
}
sub MAIN (Regex(Str) $sample) {
if ( "hello world" ~~ $sample ) {
say "hello world";
}
}
Issues
- This changes the default
Str
class which may cause unexpected behavior down the road. - Regexes passed to this work but sometimes act strange. For example:
this works:
$ ./cliRegex.raku '.*'
hello world
this does not work:
$ ./cliRegex.raku .*
Usage:
./cliRegex.raku <sample>
1