From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Duffy, Peter
Sent: 21 October 2008 12:14
To: perl-win32-users@listserv.ActiveState.com
Subject: file::spec splitpath problems

> Hi, 
> 
> I'm trying to use the File::Spec <File::Spec>  module to assist with
creating scripts which will work on both 
> linux and windows. I'm hitting a problem when I try to use the
splitpath function. According to the manual, it > should return the list
( $volume, $directories, $filename). However, when I try this under
linux (RHEL4, 
> File::Spec <File::Spec>  version 0.87):
> 
> use File::Spec::Functions <File::Spec::Functions>  qw(:ALL); 
> 
>
($volume,$directories,$filename)=splitpath("T:\subdir\scripts\testscript
.pl"); 

It's a good idea to start your code with "use strict; use warnings;". It
would also have given you a pointer to your first problem with the above
line. That is, perl doesn't know what to do with "\s". It handles "\t"
OK, as it translates it into a tab character. You probably want to
either escape the "\" characters or enclose the string in single quotes,
in order to ask perl not to treat "\" as an escape character, or even
better, change them to "/" which is more portable.

> print "volume=\'".$volume."\' directories=\'".$directories."\'
filename=\'".$filename."\'\n"; 
> exit(0); 
> 
> it gives: 
> 
> volume='' directories='' filename='T:subdirscripts      estscript.pl' 
> 
> Under windows (XP pro, active perl 5.8.8, File::Spec <File::Spec>
version 3.12) the same code gives: 
> 
> volume='T:' directories='' filename='subdirscripts      estscript.pl' 
> 
> I've hunted through the perl mailing list archives, and the web in
general, and can't find anything relevant - > which leads me to the
assumption that I'm doing something wrong (and probably silly also.)
What would be really > useful would be an example of correct usage of
the splitpath function: could someone e provide one (or any 
> other pointer to what I'm doing wrong)?

Also, perhaps you spotted in the doco for splitpath where it says "On
systems with no concept of volume, returns '' for volume". That would be
systems such as Linux. File::Spec loads the module specific to the
platform that it is running on. As such it is unlikely to understand
paths specific to a different platform.

HTH

-- 
Brian Raven 

-----------------------------------------------------------------------------------------------------------
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to