in reply to Re: DBD::CSV failing
in thread DBD::CSV failing

<sigh gauge="heavy"> ARgh.

Here's the code:

#! /usr/local/bin/perl # use DBI; use DBD::CSV; my($dh, $sh); my($row); $dh = DBI->connect("DBI:CSV:") || die "Cannot connect: ". $DBI::errstr; $dh->{'csv_tables'}->{'passwd'} = { 'eol' => '\n', 'sep_char' => ':', 'quote_char' => undef, 'escape_char' => undef, 'file' => '/etc/passwd', 'col_names' => ["login", "password", "uid", "gid", "gecos", "dir", "shell"] }; $sh = $dh->prepare("SELECT * FROM passwd") || die "Cannot prepare: ". $dh->errstr(); $sh->execute() || die "Cannot execute: ". $sh->errstr(); while ($row = $sh->fetch) { printf "%s\n", $row; }

Data is the /etc/passwd file at work which, for obvious reasons, I cannot post here.

Suffice to say it is a file of greater than one line consisting of records of the format:

user:*:[0-9]+:[0-9]+:Real Name:/dir:/path/to/shell

The output I get is the first row in the passwd file and no more.

/* relayer halo gmail */

Replies are listed 'Best First'.
Re^2: DBD::CSV failing
by bmann (Priest) on Jan 28, 2006 at 02:08 UTC
    Single quotes don't interpolate and there is no literal \n in your password file.

    Try changing the single quote to double quotes:

    'eol' => '\n', should be 'eol' => "\n",

      Well, I guess I must have tripped on that, because I have all delimited stuff in double quotes and it Just Sorta Works now.

      Thanks for your help!

      /* relayer halo gmail */
        It's not a matter of whether "the delimited stuff" is in double quotes. The fields in the data don't need to be in double quotes unless they have embedded newlines or commas or double quote characters. The field separator ';' doesn't need to be in double quotes because it's a single literal character. The only thing that *needs* to be in double quotes is the "\n" beacues as bmann++ #good eye, correctly pointed out, otherwise it will expect there to tbe a literal slash followed by a literal 'n' and the end of all your records.