in reply to Re: How to set variable names using Text::CSV?
in thread How to set variable names using Text::CSV?

Tux,

Why should I always pass binary => 1 when I am dealing with ASCII characters? I don't know what auto_diag => 1 does, so I would prefer not to use it. I also noticed that you changed the || to or, would you please tell me why? It also looks like @names keeps the order that I want, so I think I will keep it.

Have a nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^3: How to set variable names using Text::CSV?
by Tux (Canon) on Oct 16, 2009 at 06:47 UTC

    IMHO binary should have been the default when the module was created, but that was before I took over. Now we have to keep backward compatibility. There are two reasons to always pass binary

    1. You don't forget the attribute syntax (people still get that wrong)
    2. You never know when your-all-ASCII suddenly uses binary characters

    Of course, when it is your own data, and you generate it yourself, feel free to leave it out, but it is the most given solution I have to give to people that sen me mail with "Text::CSV_XS is broken" subjects.

    auto_diag is a rather new attribute that calls error_diag () at the moment the error occurs, so you will (hopefully) never wonder why something went wrong.

    There is no difference between

    my @names = @{$csv->getline ($io)}; # note the @{...} $csv->column_names (@names);

    and

    my @names = @{$csv->getline ($io)}; # note the @{...} $csv->column_names ( [ @names ] ); # extra whitespace for attention

    which is essentially the same as

    $csv->column_names ($csv->getline ($io));

    when you do not intend to use @names after the column assignment. The order is the same for all. If you need the headers later, you can still use

    my @names = $csv->column_names ();


    Enjoy, Have FUN! H.Merijn
      Why not create a new package with modern defaults?
      use Text::CSV; my $t = Text::CSV::B->new; # binary 1 by default ....