Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we work with OS-independent paths in Perl 6?

Tags:

windows

raku

Perl 6 does have classes that include common OSs for specifying paths, as well as $*SPEC which contains the file specification. New paths use by default current value of SPEC. However, it's not clear at all, from the documentation, if doing something like

mkdir IO::Path.new( 'a/b/c' );

is going to work correctly across all operating systems, or you need to specifically create OS-dependent code. Any idea?

like image 746
jjmerelo Avatar asked Sep 04 '19 06:09

jjmerelo


2 Answers

I'm trying this on Windows 7 (one of the OSes you seem to be mostly interested in according to tags), using

This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03
implementing Perl 6.d.

And it seems to work just like that

> with mkdir IO::Path.new('a/b/c') { say .e; say .absolute }
True
C:\rakudo\a\b\c

The directory is indeed created properly.

Note that IO::Path takes an IO::Spec object defaulting to $*SPEC in its constructor, so the necessary OS-dependent part is available to the object. In Rakudo the IO::Spec is indeed used by mkdir through .absolute. There also is a roast test about / in an IO::Path becoming \ on Windows.

As Elizabeth Mattijsen pointed out, Windows seems to just support forward slashes by itself. Others claim that this has been the case forever:

Actually, every version of Windows, and every version of MS-DOS from 2.0 on, has accepted "/" as a path delimiter.

like image 129
Tobias Boege Avatar answered Sep 26 '22 02:09

Tobias Boege


On a Windows 10 Enterprise VM:

C:\Users\me>c:/rakudo/bin/perl6 -e "mkdir IO::Path.new( 'a/b/c' )"

C:\Users\me>tree a
Folder PATH listing
Volume serial number is xxx
C:\USERS\ME\A
└───b
    └───c
like image 21
nxadm Avatar answered Sep 22 '22 02:09

nxadm