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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.