vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

Do I need to follow any rules when selecting the delimiter in perl?

Let say my program gives log message on error and success message with some fields, So I need to log these fields with delimiter, So I can use these log files later.

Ex: command#response#output_filename#process_id

Vinoth,G

Replies are listed 'Best First'.
Re: Delemeter Selection
by Polyglot (Chaplain) on May 19, 2009 at 04:06 UTC
    Yes. You need to select a delimiter that will not be confused with the data it is delimiting.

    In your case, you probably have white space in the log file (tabs or spaces). If that is not sufficient to delimit your log, and if you need to add something, you need to choose a delimiter that will not be in your file except as your delimiter. So, if you have dollar signs in the file, do not use that as the delimiter. If you have pipes in the file, choose something else for the delimiter.

    After that, you can always escape a special character and use it as a delimiter if necessary.

    Common delimiters are tab , space | and #. But other characters can work well also.

    Blessings,

    ~Polyglot~

Re: Delemeter Selection
by lakshmananindia (Chaplain) on May 19, 2009 at 04:06 UTC

    I feel it depends on the language you are using. Because in the language you are using, the delimiter will be some operator which does some special task. At those times you need to be careful in selecting a delimiter. The delimiter should be independent of what the data it contains.

    --Lakshmanan G.

    The great pleasure in my life is doing what people say you cannot do.


Re: Delemeter Selection
by targetsmart (Curate) on May 19, 2009 at 04:38 UTC
    Never worry about the delimiter business, use XML.

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.