Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Process Text File and Write to Database

by keszler (Priest)
on Nov 20, 2009 at 19:35 UTC ( [id://808514]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Process Text File and Write to Database
in thread Process Text File and Write to Database

This is quick, ugly, and prone to fail at the slightest change in the data, but maybe it'll get you started:
open INPUT,'<',$out_file or die "Can't open file " . $out_file . "\n$! +\n"; #Open for read while (<INPUT>) { my $name = $connect->quote($_); my $address1 = $connect->quote(<INPUT>); my $address2 = $connect->quote(<INPUT>); my $phone = $connect->quote(<INPUT>); for (<INPUT>) { next if /(Council|^Continuing|^Mapping)/; last; } my $overall = $connect->quote($_); my $inspections = $connect->quote(<INPUT>); my $staffing = $connect->quote(<INPUT>); my $quality = $connect->quote(<INPUT>); my $programs = $connect->quote(<INPUT>); my $beds = $connect->quote(<INPUT>); my $ownership = $connect->quote(<INPUT>); my $query_string = "INSERT INTO nursing_homes (name, address1, + address2, phone, overall, inspections, staffing, quality, programs, +beds, ownership) VALUES ($name, $address1, $address2, $phone, $overal +l, $inspections, $staffing, $quality, $programs, $beds, $ownership)"; #printVariables($name, $address1, $address2, $phone, $overall, + $inspections, $staffing, $quality, $programs, $beds, $ownership, $qu +ery_string); my $query_handle = $connect->prepare("INSERT INTO nursing_home +s (name, address1, address2, phone, overall, inspections, staffing, q +uality, programs, beds, ownership) VALUES ($name, $address1, $address +2, $phone, $overall, $inspections, $staffing, $quality, $programs, $b +eds, $ownership)"); $query_handle->execute(); }

You define $query_string but don't use it, and you're not checking return values for the prepare and execute calls. You must.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2025-07-12 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.