Hi perlmad,
If you move the print line one line up, i.e. into the third nested if, your output is as you expect.
BTW, there isn't really anything recursive about your code, you just have three different ifs for three different classes, which are run against all divs. Assuming you only need to select divs based on their classes that's fine, but if you also happen to need to select them based on their position in the tree you'll need different (possibly recursive) code for that.
The above fix will also get rid of all the warnings that your code would have produced had they been enabled before the fix. Since they can be quite useful in finding potential problems, you should leave warnings turned on and only disable specific ones if you know what you're doing.
Also, the way you're matching CSS classes is a potential place for your code to break, since the order of class names might change. If your HTML is static and never changes, your code should work, but otherwise you might want to look into using proper CSS selectors. For example, an alternative way to parse HTML is Mojo::DOM, which supports several CSS selectors. There were two threads about it not too long ago, How to obtain text in Mojo::DOM ? and Mojo::DOM find tag after another tag.
Hope this helps,
-- Hauke D
Update: Clarification.
In reply to Re: Nested div tag
by haukex
in thread Nested div tag
by perlmad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |