Front page | perl.beginners |
Postings from March 2002
FW: Connecting to DB
From:
Michael Gargiullo
Date:
March 28, 2002 13:32
Subject:
FW: Connecting to DB
Message ID:
NGBBJEADBDIGMPLAMOCNAEBPCCAA.gargiullo@comcast.net
OK I have the following array
@new which has the following data in it
this town
this state
zipcode
county
fips (I want discarded)
Area code
And want to insert these vars into my DB
I'm using this code:
#!/usr/bin/perl -w
use LWP::Simple;
use DBI;
use strict;
my $db="zipcodes"; #############
my $user="notshown"; # Database #
my $pass="notshown"; # Variables #
my $tablename="zips"; #############
my $insertToDB=1; #Change to zero if you don't want to write to DB
my $printToTerm=1; #Change to zero if you don't want results printed to
the terminal
my $content;
my @arr;
my @new;
my $line;
my $count=0;
$_=get("http://zipinfo.com/cgi-local/zipsrch.exe?cnty=cnty&ac=ac&zip=08550")
;#
Get Zipcode Data
@arr = /<td align=center>(.*?)<\/td>/g; # Stript Most HTML
shift(@arr); #Remove Unwanted
shift(@arr); #Data Returned
# Strip trailing </font> tag, remove fips code, and Store in array
foreach $line(@arr){
$_=$line;
/(.*.)<(.....)/;
if($count != 6){
$new[$count]=$1;
++$count;
}
}
# Insert Data into Database MS SQL SERVER 2K
if($insertToDB==1){
$dbh = DBI->connect('DBI:Sybase:server=192.168.0.2', $user,$passwd);
$dbh->do(INSERT into
$tablename(city,state,county,zip,areacode)VALUES($new[0],$new[1],$new[3],$ne
w[2],$new[5]);
$action->execute;
}
# Print to Terminal
if($printToTerm==1){
print "@new\n";
}
These are the errors I'm receiving:
Global symbol "$dbh" requires explicit package name at ./zip.pl line 32.
Global symbol "$passwd" requires explicit package name at ./zip.pl line
32.
Global symbol "$dbh" requires explicit package name at ./zip.pl line 33.
Global symbol "$action" requires explicit package name at ./zip.pl line
34.
Execution of ./zip.pl aborted due to compilation errors.
[mike@viper mike]$ ./zip.pl
Global symbol "$dbh" requires explicit package name at ./zip.pl line 32.
Global symbol "$passwd" requires explicit package name at ./zip.pl line
32.
Global symbol "$dbh" requires explicit package name at ./zip.pl line 33.
syntax error at ./zip.pl line 33, near "$tablename("
Bareword found where operator expected at ./zip.pl line 33, near ")VALUES"
(Missing operator before VALUES?)
Global symbol "$action" requires explicit package name at ./zip.pl line
34.
Execution of ./zip.pl aborted due to compilation errors.
I know that I can connect to the DB. I can connect using this script:
#!/usr/bin/perl
use DBI;
$user='notshown';
$passwd='notshown';
$dbh = DBI->connect('DBI:Sybase:server=192.168.0.2', $user, $passwd);
$dbh->do("use Northwind");
$action = $dbh->prepare("sp_help");
$action->execute;
$rows = $action->rows;
print "rows is $rows\n";
while(@first = $action->fetchrow_array){
foreach $field (@first){
print "$field\t";
}
print "\n";
}
exit(0);
Any light you can shed on this would be greatly appriciated. Thank you
Mike
_______________________________________________________________
Composed with Pine 4.2.1
FACT: George Washington was actually the 8th President of the United
States, but the first under our current constitution.
-
FW: Connecting to DB
by Michael Gargiullo