#!c:/perl/bin/perl -w use strict; use DBI; my $DEBUG = 0; my $hfnetchk_dir = "c:/progra~1/shavli~1/hfnetchk"; my $hfnetchk = "${hfnetchk_dir}/hfnetchk.exe"; my $hfnetchk_switches = "-o tab -s 2"; my $db_dir = "${hfnetchk_dir}/hfnc_db"; my $table = "hfnetchk"; my $db_file = "${db_dir}/${table}.dbf"; my $time = scalar localtime; my $fh; open $fh, "$hfnetchk $hfnetchk_switches |"; my @lines = <$fh>; close $fh; chomp @lines; my @fieldnames = split "\t", shift @lines; dprint("fieldnames=", join(" ", @fieldnames)); my $fieldnumber = $#fieldnames; dprint("fieldnumber=", $fieldnumber); my @items = (); my ($l, $f, $i); for $l (@lines) { my @i = map { s/"/'/g; $_ } split(/\t/, $l); my %h = (); for $f (0..$fieldnumber) { $h{$fieldnames[$f]} = $i[$f]; } push @items, \%h; } if (not -d $db_dir) { mkdir $db_dir; } my $dbh = DBI->connect("dbi:XBase:${db_dir}"); my ($sth, $sql); if (not -f $db_file) { $sql = "create table ${table} (\n" . " logtime varchar(25),\n" . " machine varchar(50),\n" . " product varchar(50),\n" . " bulletin varchar(10),\n" . " qnumber varchar(10),\n" . " status varchar(50)\n" . ")"; dprint("sql=", $sql); $sth = $dbh->prepare($sql); my $rv = $sth->execute; dprint("rv=", $rv); } for $i (@items) { $sql = "insert into ${table} (" . "logtime, machine, product, bulletin, qnumber, status" . ") values ('" . $time . "', '" . $i->{"Machine Name"} . "', '" . $i->{"Product"} . "', '" . $i->{"Bulletin"} . "', '" . $i->{"Q Number"} . "', '" . $i->{"Status"} . "')"; dprint("sql=", $sql); $sth = $dbh->prepare($sql); my $rv = $sth->execute; dprint("rv=", $rv); } my $rv = $dbh->disconnect; dprint("rv=", $rv); sub dprint { if (not $DEBUG) { return; } print join('', map { $_ || 'undef' } @_), "\n"; }