in reply to what type of deliminator is used in tabular file.

wst  is there a way to find out from a file, what type of deliminator is used
so enduser can change this deliminator to something else for that file


There is a CPAN-Module Data-CTable which supposedly does this:

Data::CTable reads and writes any tabular text file format including Merge, CSV, Tab-delimited, and variants. It transparently detects, reads, and preserves Unix, Mac, and/or DOS line endings and tab or comma field delimiters -- regardless of the runtime platform.

I can't tell if it really works the way you need it.

Regards

mwa
  • Comment on Re: what type of deliminator is used in tabular file.

Replies are listed 'Best First'.
Re^2: what type of deliminator is used in tabular file.
by CountZero (Bishop) on Sep 25, 2007 at 19:14 UTC
    But it will only detect the field delimiter if it is a TAB or a COMMA:
    _FDelimiter is the field delimiter between field names in the header row (if any) and also between fields in the body of the file. If undef, read() will try to guess whether it is tab "\t" or comma <",">, and set this parameter accordingly. If there is only one field in the file, then comma is assumed by read() and will be used by write().

    To guess the delimiter, the program looks for the first comma or tab character in the header row (if present) or in the first record. Whichever character is found first is assumed to be the delimiter.

    If you don't want the program to guess, or you have a data file format that uses a custom delimiter, specify the delimiter explicitly in the object or when calling read() or make a subclass that initializes this value differently. On write(), this will default to comma if it is empty or undef.

    Its use is therefore fairly limited if you venture outside of the world of the comma- or tab-separated type of files.

    A somewhat more flexible module is Text::CSV::DetectSeparator which can distinguish between the following delimiters , ; . : # (it strangely omits the tab-delimiter).

    Text::CSV::Separator is even more flexible. Its standard list of delimiters is , ; : | \t, but it accepts a list of other candidates and can even use an "excluded" list of characters.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James