Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:21:38+00:00 2026-06-13T05:21:38+00:00

I am using DBD::CSV to show csv data. Sometimes the file doesn’t contain column

  • 0

I am using DBD::CSV to show csv data. Sometimes the file doesn’t contain column names, so we have to manually define it. But after I followed the documentation, I got stuck with how to make the attribute skip_first_row work. The code I have is:

#! perl
use strict;
use warnings;
use DBI;

my $dbh = DBI->connect("dbi:CSV:", undef, undef, {
    f_dir            => ".",
    f_ext            => ".txt/r",
    f_lock           => 2,
    csv_eol          => "\n",
    csv_sep_char     => "|",
    csv_quote_char   => '"',
    csv_escape_char  => '"',
    csv_class        => "Text::CSV_XS",
    csv_null         => 1,
    csv_tables       => {
        info => {
            file => "countries.txt"
        }
    },  
    FetchHashKeyName => "NAME_lc",
}) or die $DBI::errstr;

$dbh->{csv_tables}->{countries} = {
  skip_first_row => 0,
  col_names => ["a","b","c","d"],
};

my $sth = $dbh->prepare ("select * from countries limit 1");
$sth->execute;
while (my @row = $sth->fetchrow_array) {
  print join " ", @row;
  print "\n"
}
print join " ", @{$sth->{NAME}};

The countries.txt file is like this:

AF|Afghanistan|A|Asia
AX|"Aland Islands"|E|Europe
AL|Albania|E|Europe

But when I ran this script, it returns

AX Aland Islands E Europe
AF AFGHANISTAN A ASIA

I expected it to either return:

AF AFGHANISTAN A ASIA
a b c d

or

a b c d
a b c d

Does any know what’s going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:21:39+00:00Added an answer on June 13, 2026 at 5:21 am

    For some reason, contrary to the documentation, it doesn’t see the per-table settings unless you pass them to connect.

    my $dbh = DBI->connect("dbi:CSV:", undef, undef, {
        f_dir            => ".",
        f_ext            => ".txt/r",
        f_lock           => 2,
        csv_eol          => "\n",
        csv_sep_char     => "|",
        csv_quote_char   => '"',
        csv_escape_char  => '"',
        csv_class        => "Text::CSV_XS",
        csv_null         => 1,
        csv_tables       => {
            countries => {
                col_names => [qw( a b c d )],
            }
        },
        FetchHashKeyName => "NAME_lc",
    }) or die $DBI::errstr;
    

    Then it works fine:

    my $sth = $dbh->prepare ("select * from countries limit 1");
    $sth->execute;
    
    print "@{ $sth->{NAME} }\n";      # a b c d
    
    while (my $row = $sth->fetch) {
        print "@$row\n";              # AF Afghanistan A Asia
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using DBD::CSV to show csv data. The code I have is: #!
I am DBD::SQLite to insert some data in SQlite3 db using perl. I have
I am using a DBD::SQLite in memory database. I have defined the following indexes
I am going to be writing to a MySQLite database file, using Perl's DBD:SQLite
Using Java,I have to fetch multiple sets of values from an XML file to
I'm using the Cacti script/command method to collect data. I have a perl script
I have installed DBD::Pg version 2.17.1 but still still getting error while using below
I'm using DBD::Oracle in perl, and whenever a connection fails, the client generates a
I've got a problem with the module DBD::CSV v0.30. Since a update to the
Hi I am using DBD::Oracle in my script to query into oracle database. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.