Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: DBD::CSV failing

by bsdwolf (Initiate)
on Jan 28, 2006 at 01:24 UTC ( #526120=note: print w/replies, xml ) Need Help??


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.

--*greywolf;
/* 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!

      --*greywolf;
      /* 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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2021-11-30 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?