Perl DBI wrote:
>
> i thought it's like DBD::CSV where i can connect to a CSV file and use
> SQL. how about DBD::RAM?
Actually DBD::RAM has been replaced by DBD::AnyData, and both of them
will do what you want -- allow you to run SQL on a .htpasswd file.
Here's how:
use DBI;
my $dbh = DBI->connect('dbi:AnyData:(RaiseError=>1)');
my $flags = {
col_names => 'user,pass',
sep_char => ':'
};
my $file = '.htpasswd'; # this could also be an absolute path
# or even a url of a file on a remote machine
$dbh->func( 'htp', 'CSV', $file, $flags, 'ad_catalog');
print $dbh->selectrow_array("SELECT pass FROM htp WHERE user = 'jeff'");
#
# ... any other DBI commands using AnyData's subset of SQL
In addition to providing SQL access, this method has other advantages
over the Text_CSV approach including things like flock (if supported on
your platform) and verbose error reporting of file access problems. You
could of course also code those by hand, but why bother?
--
Jeff