in reply to how do I get the directory name from the pathnames
Use splitpath from File::Spec and split:
use strict; use warnings; use File::Spec; while (<DATA>) { chomp; my @subs = split /\\/, (File::Spec->splitpath ($_)) [1]; print "sub dir is: $subs[2]\n" if $#subs > 1; print "No sub dir in $_\n" if $#subs <= 1; } __DATA__ C:\dir1\ C:\dir1\subdir1\ C:\dir1\subdir1\subdir2\
Prints:
No sub dir in C:\dir1\ sub dir is: subdir1 sub dir is: subdir1
|
|---|