Hi flieckster,
For portable filename handling, I recommend the core module File::Spec, or from CPAN Path::Class:
use Data::Dumper; $Data::Dumper::Useqq=1; $Data::Dumper::Terse=1; use File::Spec::Functions qw/catdir catpath/; print Dumper( catdir('','photorepos','Perl','Mother','WorkLoad') ); # the following volume spec is ignored in *NIX print Dumper( catpath('C:', catdir('','photorepos','Perl','Mother','WorkLoad')) ); use Path::Class qw/file dir/; print Dumper( dir('C:\\')->subdir('photorepos')->subdir('Perl') ->subdir('Mother')->subdir('WorkLoad').'' ); my $dir = dir('C:\\','photorepos','Perl','Mother','WorkLoad'); print "Path: ", Dumper( "$dir" ); print $dir->is_absolute ? "Is Absolute\n" : "Is Relative\n"; print "Volume: ", $dir->volume, "\n"; print "Dir List: ",Dumper( [$dir->dir_list] );
I admit I haven't worked with volume specs in either module, and I don't have a Windows machine handy at this moment, so the above may need some tweaking in that respect.
Update 2016-10-29: I tested this on a Windows machine and apparently, in File::Spec, the volume argument to catpath needs to be 'C:', not just 'C', while in Path::Class, the volume needs to be specified as 'C:\\' for things to work properly (unfortunately it seems neither of these points are mentioned in the docs). I updated the above code accordingly and added some more output. The Path::Class code does not work the same under Linux as under Windows: since in Linux "C:\" is a valid name for a directory, that path component is treated like just another regular directory. Here are the outputs:
# Windows "\\photorepos\\Perl\\Mother\\WorkLoad" "C:\\photorepos\\Perl\\Mother\\WorkLoad" "C:\\photorepos\\Perl\\Mother\\WorkLoad" Path: "C:\\photorepos\\Perl\\Mother\\WorkLoad" Is Absolute Volume: C: Dir List: ["", "photorepos", "Perl", "Mother", "WorkLoad"] # Linux "/photorepos/Perl/Mother/WorkLoad" "/photorepos/Perl/Mother/WorkLoad" "C:\\/photorepos/Perl/Mother/WorkLoad" Path: "C:\\/photorepos/Perl/Mother/WorkLoad" Is Relative Volume: Dir List: ["C:\\", "photorepos", "Perl", "Mother", "WorkLoad"]
Hope this helps,
-- Hauke D
In reply to Re: moving from mac to PC (updated!)
by haukex
in thread moving from mac to PC
by flieckster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |