in reply to recursive split

Split does not modify the original scalar; it returns a list. If you want to split the elements of that list, you need to split each of the elements and then collect those mini lists into a bigger list.

Write yourself a subroutine that takes a list, splits each of the things in that list, and pushes the results into a big list to return.

You can then call that sub as many times as you like without having to use recursion (starting with a list of 1 items, your original string).

Replies are listed 'Best First'.
Re^2: recursive split
by newbio (Beadle) on Sep 03, 2009 at 17:57 UTC
    Thanks for your reply. Actually, I need those passes to look like the way as shown above so that I can do some processing to the content within the parenthesis if required at each recursive step. I tried shellwords but that also does not work here.
      Sounds like you want a queue of things to do next then.
      • List of things to process in the next iteration = startstring
      • While there are things to process in the next iteration
        • things to process this iteration = things to process next iteration. Things to process next iteration = ()
        • while things to process this iteration
          • shift list of things to do this iteration, and split that thing
          • ponder the split thing and print any revelations.
          • add to the list of things to process next iteration if appropriate
      You probably don't want to do recursion if you want to print everything from one level before moving on to the next.