You have 2 problems. The first is that Windows volume names include the colon, so you should have said $volume = 'C:'
. The second is that you specified a relative path, so you got a relative path. If you want an absolute path, you have to give one:
use 5.010;
use File::Spec;
my $volume = 'C:';
my $path = File::Spec->catpath($volume,
File::Spec->catdir('', 'panel', 'texts'), 'file');
say $path;
On Windows, that will print C:\panel\texts\file
, and on Unix it will say /panel/texts/file
.
Note that it's perfectly legitimate to have a relative path with a volume name on Windows:
File::Spec->catpath('C:',
File::Spec->catdir('panel', 'texts'), 'file');
will give you C:panel/texts/file
, which means panel/texts/file
relative to the current directory on drive C:
. (In Windows, each drive has its own current directory.)