Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Text::CSV_XS - proposed new interface

by uwevoelker (Pilgrim)
on Dec 16, 2004 at 11:43 UTC ( #415331=note: print w/replies, xml ) Need Help??


in reply to Text::CSV_XS - proposed new interface

$row = $c->fetchrow_hashref
Where do the column names come from? I would like the module to use the first line. Maybe we could implement a mapping (column_name => hash_key or column_name => '' to ignore this column).
The old interface really is strange...

Bye, Uwe

Replies are listed 'Best First'.
Re^2: Text::CSV_XS - proposed new interface
by jZed (Prior) on Dec 16, 2004 at 16:16 UTC
    > Where do the column names come from?

    Good question! My thought was that if the user specifies a comma-separated columns attribute in the new() flags, those will be the column names and the first row of the file will be treated as data but that if none is supplied, the first row of data will be treated as the column names.

    > The old interface really is strange

    Yep, though very usable once you get used to it. (I inherited the interface from the module's original author). The odd thing is that in the six years the module has been on CPAN, no one has mentioned this. Bart and Diotalevi griped loudly in the CB, so I listened. Griping++. (polite griping)++++. (sending messages to CPAN authors that they have strange interfaces with examples of what's strange and what might be better)++++++.

      > Where do the column names come from? Good question! My thought was that if the user specifies a comma-separated columns attribute in the new() flags, those will be the column names and the first row of the file will be treated as data but that if none is supplied, the first row of data will be treated as the column names.
      Think about this part very carefully. There are continual problems with DBD::CSV, because the column descriptions that work well in spreadsheets don't map directly to valid SQL column names. "Profit & Loss" works in a spreadsheet, but has to become something like "PROFIT_AND_LOSS" in a database.

      By the way, allowing embedded EOLs by default sounds good. It would also be good to allow extended characters by default. The first thing I tell everyone about Text::CSV_XS is that they need to turn "binary" on...

        > There are continual problems with DBD::CSV, because the
        > column descriptions that work well in spreadsheets don't
        > map directly to valid SQL column names.

        Text::CSV_XS won't care about valid SQL names, that part is added by DBD::CSV and is easily handled. From the DBD::CSV pod:

        "you can supply an array ref of column names with the col_names attribute."

        > It would also be good to allow extended characters by
        > default.

        Yes, that will be the case.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://415331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-05-29 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?