Well, I'm glad that I got right what you wanted. =) Now, to explain the substitution...
my $str = "/One/Two/Three"; # Start with the whole thing in the array. You could # start with @paths = () if you'd rather not include # the current directory/path/category/whatever. my @paths = ($str); while( # Spreading this out so I can comment it... $str =~ s[ ^ # Match from the start of the string... ( # Save this in $1 / # The first / .+ # Followed by one or more <anything>'s # (including /'s!!), all the way up to # the last / (see below) ) # Don't save anything else in $1 / # The very last / in the string. This # is what causes the above .+ to stop # before the end of the string. [^/]* # We want an optional word after # the last / but NOT /'s (otherwise # it wouldn't be the last one, would it?) $ # Make sure don't stop before the end # of what's left of the string. ][$1]x # Replace it all with $1, which contains # everything up to (but not including) # the last /. Note the x option, let's us # include comments and space it out. ) { # Push the current version of $str onto the list. # It's whatever we have left after chopping off # the last word and it's /. push @paths, $str; }
You're right. That's not a very pretty substitution. :-) If I can think of a cleaner way of doing it, I'll post it. Hope that helps.
bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.
In reply to (bbfu) (further explanation) Re(3): Messing with (my head) a substring
by bbfu
in thread Messing with a substring
by psypete
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |