In article <[EMAIL PROTECTED]>, Sudarshan Raghavan wrote:use File::Spec;
[EMAIL PROTECTED] wrote:
hello to everyone. when i have a path like that:
/usr/X11R6/lib/X11/locale
how can i cut this path into strings like that:
/ /usr /usr/X11R6 /usr/X11R6/lib /usr/X11R6/lib/X11 /usr/X11R6/lib/X11/locale
You have multiple options 1) split (perldoc -f split) 2) index and substr (perldoc -f index, perldoc -f substr) 3) File::Basename module (perldoc File::Basename)
Example using File::Basename #!/usr/bin/perl use strict; use warnings; use File::Basename;
strip_path (/usr/X11R6/lib/X11/locale); sub strip_path { strip_path (dirname ($_[0])) if ($_[0] ne '/');
For portable code code change this to strip_path (dirname ($_[0])) if ($_[0] ne File::Spec->rootdir);
print $_[0], "\n";[...]
}
I thought that the purpose of File::Basename is platform portability. It seems here that you are only using this for half the job. Is there another function in File::Basename (I didn't find one) or another module that also splits the dir-path? (for example producing @dirname so that $dirname[0] is the top level, $dirname[1] is the next down, etc.?
There is a splitdir function (File::Spec->splitdir). This is similar to split ('/', $your_path) on unix except it is portable. I am not aware of any function that will do what you are asking for.
-K
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]