http://qs1969.pair.com?node_id=317454


in reply to recursive parsing techniques

Naturally, being the old fogey that I am, I'd probably write my own recursive parser for this sort of thing. I know, I know, is it false laziness or false impatience? Well, anyhow, I can make it work. Writing my own in the past, I've noticed a couple of things: one, you need to have a clear mental picture of when the recursive call needs to happen; and two, you need to make quite sure that the routine called recursively will exit! Both of those have bitten me over the years. Let me give you a trivial, useless example that doesn't relate to what you're doing:
a * (b - d + (e / f) - 7) + 3
This is trivial for recursive parsing, I know, but it makes the point: you've got to call the routine when you come to an '(', and you've got to exit when you come to an ')'. Not doing either of those will most likely result in hangs and/or rubbish. I know, I've tried. In the case you're showing, looks to me like you want to recurse (call the routine you're in) on "BEGIN:VCARD" and return on "END:VCARD". What that ends up meaning is that you write the routine to parse one VCARD, and to add that one to the hash. Oh, yeah, and you may want to verify that your data is healthy, so there are as many ENDs as BEGINs. Remember, "To iterate is human, to recurse divine."