Hi Brian, Thanks very much for that. Apologies for missing the \s and \t - I should have spotted those: I take your point about using "strict" and "warnings". Almost immediately after sending the original post, I noticed that I'd used double-quotes and tried replacing them with single-quotes: however, in this case, splitpath put the entire path into the $filename slot.
I did see the bit in the doc about $volume being set to '' in systems with no concept of a volume. However, my assumption was that, in my example, splitpath would ignore the "T:" and split the rest into path and filename. Basically, given that this module is allegedly to assist with portability across platforms, I would have thought that the parsing would be identical on all platforms, and be comprehensive enough to recognise all supported formats: only the output would be in terms of the current platform. There doesn't seem to be a lot of point in each platform-specific submodule only being able to recognise the format native to that platform. Regards, Peter -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brian Raven Sent: 21 October 2008 13:01 To: [email protected] Subject: RE: file::spec splitpath problems From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Duffy, Peter Sent: 21 October 2008 12:14 To: [email protected] 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 [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
