in reply to Recursive Function To Parse File For Generating Hash

You could certainly write a parser using Parse::RecDescent, but coming up with your own format to describe your data is almost always a bad idea.

Why? Because the devil's in the detail. What happens if a value contains a literal "{"? You'll have to escape it with something like "\". What if your data contains a literal "\", then? How do you break lines? How to add comments?

These kinds of problems have been solved 1000 times already. A format like YAML should be expressive enough for your needs, so why not use something that's been proven to work?

  • Comment on Re: Recursive Function To Parse File For Generating Hash

Replies are listed 'Best First'.
Re^2: Recursive Function To Parse File For Generating Hash
by dimar (Curate) on Nov 05, 2004 at 21:05 UTC

    Not to deviate from the original topic, nor to disparage any of the points in your excellent response...

    but there are other alternatives beside using 'escape characters' as a method to distinguish delimiters from message content.

    YAML, for example, allows indentation.

    PERL, for example, allows user-definable alternate delimiters

    print q/"Hello-World"/; print q~"Hello/World~; print q!"Hello-/-World"!; print q§"Hello-/-World!"§;

    True, the devil is still in there, since you still have to make sure that your 'message-space' characters are always orthogonal to your 'delimiter-space' characters. Just making the point that 1) "escape characters" (as a typographical and programming convention) *suck*; and 2)This suckage is yet another of the problems already solved by perl, and YAML and Ruby (and others, if there are any).