I'd like to do the following in raku on windows
raku -n -e ".say if /mydatabegin/;" *.file
Failed to open file C:\..\*.file: Invalid argument
The glob isn't interpreted as a glob. I assume that's because windows requires your programs to do the globbing yourself? So is there a pre-processing directive or function or even a switch I might have missed or redirect or something that allows the glob to be expanded while keeping the simplicity of the -n (or -p) and -e switches?
Obviously, I can change it to a full program by removing the -n (or -p), just using -e to specify a main, and loop on the glob results. But I really like -n.
PS. I'm literally just learning raku, and was surprised this didn't work out of the box. So examples of full programs with easy syntax work also. But I really like -n..
Edit: re @chenyf
raku -e ".say for $*ARGFILES" *.file
Same error. Related:
raku -e ".say for $*ARGFILES.lines" *.file
Same error.
raku -e "use IO::Glob; .say for glob('*.file')"
Worked as expected! Expanding:
raku -e "use IO::Glob; .say for glob('*.file').lines"
No such method 'lines' for invocant of type 'IO::Glob'
Getting closer - perhaps expanding on this is a good enough workaround. But returning to one line glory attempts:
raku -e "use IO::Glob; .say for glob($*ARGFILES)" test.file
Cannot resolve caller glob(IO::ArgFiles:D); none of these signatures match.
Ok - let's retreat back to the safety of strings:
raku -e "use IO::Glob; .say for glob($*ARGFILES.Str)" test.file
Yes! SO..:
raku -e "use IO::Glob; .say for glob($*ARGFILES.Str).lines" test.file
No such method 'lines' for invocant of type 'IO::Glob'
I clearly need to read more of the manual. But let's retreat a little and see if my use case works:
raku -e "use IO::Glob; .say for glob($*ARGFILES.Str)" *.file
Failed to open file C:\..\*.file: Invalid argument
The same error I started off with. Could this just be a raku on windows error?
Edit:
raku -MIO::Glob -e "my @files = (map { glob($_).dir }, @*ARGS).flat; for @files -> $file { say $_ for $file.lines }" *file *file2 *5
I have three sets of files. I can almost live with this solution - except for some reason the lines are being printed with "s
Any ideas on shortening, and getting rid of the quotes?
EDIT Working around the auto-globbing of the $*ARGFILES variable:
raku -MIO::Glob -n -e "BEGIN { @*ARGS = (map { glob($_) }, @*ARGS).flat }; .say" *.file *.file2
This has the advantage of still looking like the original one liner; it uses -n! It just had to do the globbing that seems to be a bug when $*ARGFILES is created.
raku -MIO::Glob -e "BEGIN { @*ARGS = (map { glob($_) }, @*ARGS).flat }; .say for $*ARGFILES.lines" *.file *.file2
Converting to $*ARGFILES.lines above shows that $*ARGFILES gets its values from @*ARGS dynamically.
EDIT
lastly, it turns out the glob function doesn't work with directories, at least on windows (the documentation has an example that simply doesn't work).
#Example from https://github.com/zostay/raku-IO-Glob
for glob("src/core/*.pm") -> $file { say ~$file }
#mine that doesn't work
raku -MIO::Glob -e "for glob('..\*.file') -> $file { say ~$file }"
#mine that does work.
raku -MIO::Glob -e "for glob('*.file').dir('..') -> $file { say ~$file }"
#And therefore the final modification of the script above:
raku -MIO::Glob -e "BEGIN { @*ARGS = (map { glob(.IO.basename).dir(.IO.dirname) }, @*ARGS).flat }; .say for $*ARGFILES.lines" ..\*.file
$*ARGFILES
helps, for example: andrewshitov.com/2018/12/24/… – Nephographraku -e '$*ARGFILES.lines.say;' *.txt
andraku -e '.say for $*ARGFILES.lines;' *.txt
work on my older MacOS system. The first one-liner returns each*.txt
file on a single line, and the second one-liner gives a linewise return indistinguishable fromcat
(each returning five*.txt
files from my current directory). – Tragedyraku -ne ".say if /mydatabegin/;" *.txt
works fine here (note initial.
dot). – Tragedyraku -e '.lines.say for $*ARGFILES;' *.txt
works on MacOS. Guessingraku -MIO::Glob -e ".lines.say for glob($*ARGFILES.Str)" *.file
should work for you. Maybe try slash-escaping the "*" in$*ARGFILES
: either$\*ARGFILES
or$/*ARGFILES
? – Tragedy$*ARGFILES
both have meaning. I'm just wondering if you have some sort of Window's Service that inspects your command line input? For some Raku one-liners when entering them on the Vim command line I've had to escape things like stray!
exclamation marks. Wondering if you're having a similar issue with*
on Windows? Also, wondering if you could tell us you Windows version? – Tragedyglob
in Raku's "P5-to-P6" glossary, there seems to have been a design decision NOT to implementglob
in Raku. – Tragedydir()
works fine on MacOS without any extra modules (e.g.IO::Glob
). Also, the last line of code you presented contains a call to.dir
, which appears to be doing all the heavy-lifting. Note Raku doesn't have aglob()
function in core so what theIO::Glob
module appears to do is use/abusedir()
calls to simulate Perl5'sglob
function. Hopefully theIO::Glob
module developer will chime in. – Tragedy