makamaka / Text-CSV

comma-separated values manipulator
24 stars 19 forks source link

Text::CSV man page should mention something about comments #54

Open jidanni opened 3 years ago

jidanni commented 3 years ago

Emacs has

csv-comment-start is a variable defined in ‘csv-mode.el’.
Its value is "#"

  Automatically becomes buffer-local when set.

Documentation:
String that starts a comment line, or nil if no comment syntax.
Such comment lines are ignored by CSV mode commands.
This variable is buffer local; its default value is that of
‘csv-comment-start-default’.  It is set by the function
‘csv-set-comment-start’ -- do not set it directly!

Therefore the Text::CSV man page should mention something about comments. E.g., "Not allowed!"

jidanni commented 3 years ago

This example on the man page,

        while (my $row = $csv->getline ($fh)) {
            $row->[2] =~ m/pattern/ or next; # 3rd field should match
            push @rows, $row;
            }

shows how to kick out lines after processing. It would be nice to do it also before processing.

jidanni commented 3 years ago

Or say "It is 1000 times easier to do

$ grep -v ^# file.csv > file.csv.tmp

and then read that, then all other ways."

jidanni commented 3 years ago

OK, for headers => "auto" users, as long as the first line of the file isn't a comment, one can use:

my $aoh = csv(
    in      => pop,
    headers => "auto",    # strict => 1 alas, can't use here, as our comments are being parsed
    filter  => {
        1 => sub { !m/^#/ },    # jump over commented lines
    }
);
jidanni commented 3 years ago

OK, that is for commenting out entire lines. Now we turn to the case of how to add a comment to the ends of lines, like e.g., on can do in Perl itself. So perhaps mention this hack: zoom-levels,projection-false-origin-x,projection-false-origin-y,update-delay,type,server,comment

comment can contain anything, except a comma...