in reply to Messing with a substring

The nodes in this thread have focused on using regexes and substr to parse a directory path. IMHO, it might be a better idea to use a module called File::Spec, which is specifically designed for this, and works across a few different platforms, which is a nice bonus.

Here's an example script using this module to produce the output you're looking for:

#!/usr/bin/perl -wT use strict; use File::Spec; use Data::Dumper qw(Dumper); use constant PATH => '/One/Two/Three'; #split up the path into directory segments my @dirs = File::Spec->splitdir(PATH); my @paths; while(my $path = File::Spec->catfile(@dirs)) { push @paths, $path; pop @dirs; } print Dumper(\@paths);

which prints out:

$VAR1 = [ '/One/Two/Three', '/One/Two', '/One' ];