I've written a script to read in a list of nursing homes that was copied and pasted off the web. I pull this file in and write an output file that removes empty lines. I then pull the output file back in, and now I want to step through it and write certain elements to a database. There are three lines that contain information that I want to skip, as shown by the matches. I've been doing a lot of troubleshooting and can't seem to figure out where I've gone wrong. When I run the code, I get no errors, but no data in the database either.
#!c:/xampp/perl/bin/perl use strict; use warnings; use DBI; use dbConnect_nursing; sub printVariables(@_) { foreach my $variable (@_) { print $variable . "\n"; } print "###############################################\n"; } sub processLine { my @temp; chomp($_[0]); unshift(@temp, $_[0]); my $var = shift(@temp); return $var; } ################################### connect to the database ########## +################################## # data source name my $dsn = "DBI:$dbConnect::db_platform:$dbConnect::db_database:$dbConn +ect::db_host:$dbConnect::db_port"; # perl DBI connect my $connect = DBI->connect($dsn, $dbConnect::db_user, $dbConnect::db_p +w, {'RaiseError' => 1}); ################################### connect to the database ########## +################################## my @file_array; my $in_file = "c:\\nursing_homes.txt"; my $out_file = "c:\\nursing_homes_out.txt"; if (-e $out_file) { unlink $out_file; } open INPUT,'<',$in_file or die "Can't open file " . $in_file . "\n$!\n +"; #Open for read open OUTPUT,'>',$out_file or die "Can't open file " . $out_file . "\n$ +!\n"; #Open for write while (<INPUT>) { chomp ($_); next if $_ =~ /^\s*$/; # skip over blank lines print OUTPUT $_ . "\n"; } close INPUT; close OUTPUT; open INPUT,'<',$out_file or die "Can't open file " . $out_file . "\n$! +\n"; #Open for read while (<INPUT>) { my $name = $connect->quote($_); next; my $address1 = $connect->quote($_); next; my $address2 = $connect->quote($_); next; my $phone = $connect->quote($_); next; next if (($_ =~ /^.*Council.*$/) || ($_ =~ /^Continuing.*$/) | +| ($_ =~ /^Mapping.*$/)); next if (($_ =~ /^.*Council.*$/) || ($_ =~ /^Continuing.*$/) | +| ($_ =~ /^Mapping.*$/)); next if (($_ =~ /^.*Council.*$/) || ($_ =~ /^Continuing.*$/) | +| ($_ =~ /^Mapping.*$/)); my $overall = $connect->quote($_); next; my $inspections = $connect->quote($_); next; my $staffing = $connect->quote($_); next; my $quality = $connect->quote($_); next; my $programs = $connect->quote($_); next; my $beds = $connect->quote($_); next; my $ownership = $connect->quote($_); next; 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(); } close INPUT; $connect->disconnect(); __END__
Sample data is below:
AARON MANOR REHABILITATION & NURSING CENTER 100 ST CAMILLUS WAY FAIRPORT, NY 14450 (585) 377-4000 Resident Council Mapping & Directions 4 out of 5 stars 4 out of 5 stars 3 out of 5 stars 4 out of 5 stars Medicare and Medicaid 140 For profit - Corporation ABSOLUT CTR FOR NURSING & REHAB ALLEGANY LLC 2178 NORTH FIFTH STREET ALLEGANY, NY 14706 (716) 373-2238 Resident & Family Councils Mapping & Directions 3 out of 5 stars 4 out of 5 stars 1 out of 5 stars 4 out of 5 stars Medicare and Medicaid 37 For profit - Corporation ABSOLUT CTR FOR NURSING & REHAB AURORA PARK LLC 292 MAIN STREET EAST AURORA, NY 14052 (716) 652-1560 Resident Council Mapping & Directions 1 out of 5 stars 1 out of 5 stars 2 out of 5 stars 4 out of 5 stars Medicare and Medicaid 320 For profit - Corporation ABSOLUT CTR FOR NURSING & REHAB DUNKIRK LLC 447 449 LAKE SHORE DRIVE WEST DUNKIRK, NY 14048 (716) 366-6710 Resident Council Mapping & Directions 1 out of 5 stars 2 out of 5 stars 1 out of 5 stars 2 out of 5 stars Medicare and Medicaid 40 For profit - Corporation
In reply to Process Text File and Write to Database by spickles
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |