use strict;
use warnings;
my @files = (
'/a/b/12.jpg',
'/a/b/c/d/12.jpg',
'/a/b/c/12.jpg',
'/a/b/e/12.jpg',
'/a/b/c/f/12.jpg',
'/a/b/e/12.jpg',
'/a/b/12.jpg',
'/b/12.jpg',
);
my $cp = 0;
foreach my $file (@files) {
$file =~ m#(.*/)#;
$cp = $1 if $cp eq '0'; # only for the first run
$cp = $1 if (length($cp) > length($1));
print "$1 $file\n";
}
print "Common Path is $cp\n";
use strict;
use warnings;
use Data::Dumper;
my $h = {
'/' =>
{a => [12, 13],
b => [14]},
};
print Dumper $h;