(edited to fix unclear statement)
Update 2: somehow, I never noticed splitdir
As jellisii2 said, File::Spec can be helpful.
In this case, File::Spec::splitpath would still have given "logfile.txt " because it can't know the extra space is not part of the file name.
Otherwise, File::Spec::splitpath is a good way to break down paths.
The potential negative to File::Spec::splitpath is that it only splits a path into volume, directory-path and filename. If you need to further split the directory path, you have to use a loop:
# this is NOT tested my ($vol, $dir, $file) = File::Spec::splitpath($path); my $temp_path = $path; my $temp_dir; my $temp_vol; my @dirs; while ($dir neq $temp_path) { $temp_path = $dir; ($temp_vol, $dir, $temp_dir) = File::Spec::splitpath($temp_path); unshift @dirs, $temp_dir; } unshift(@dirs, $dir) unless (@dirs > 0);
In reply to Re: open file error
by RonW
in thread open file error
by t-rex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |