| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use DBI; |
| 7 |
|
| 8 |
my $dbh = DBI->connect ("DBI:CSV:"); |
| 9 |
$dbh->{csv_tables}{passwd} = { |
| 10 |
sep_char => ":", |
| 11 |
quote_char => undef, |
| 12 |
escape_char => undef, |
| 13 |
file => "/etc/passwd", |
| 14 |
col_names => [qw( login password uid gid realname directory shell )], |
| 15 |
}; |
| 16 |
my $sth = $dbh->prepare ("SELECT * FROM passwd"); |
| 17 |
$sth->execute; |
| 18 |
my %fld; |
| 19 |
my @fld = @{$sth->{NAME_lc}}; |
| 20 |
$sth->bind_columns (\@fld{@fld}); |
| 21 |
while ($sth->fetch) { |
| 22 |
printf "%-14s %5d %5d %-25.25s %-14.14s %s\n", |
| 23 |
@fld{qw( login uid gid realname shell directory )}; |
| 24 |
} |