http://www.perlmonks.org?node_id=232026

KyleYankan has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm in the process of re-vamping my site, and am having a wee bit of trouble. I use a template on my site, and simply grab the data to display out of a .inc file, using PHP. I want to transfer this all over to a perl site, kinda like perlmonks. I really like the idea, plus I'm much, MUCH, better at perl, than PHP. My folders are layed out like so: kylesdesktop.com ./cgi-bin/ ./public_html/ ./content/ ./other_stuff move.pl is in the cgi-bin, and all the *.inc's are in the content folder. My problem is that my script goes into an infinite loop, or just hangs. This messed me up, becuase it hangs with the MySQL connection open, and I can't connect more than X times to my server. This means my website goes down when it runs. Here's the code to transfer script. Sorry for obvius mistakes, I'm tired and grumpy. Wrote it late last night, and haven't slept since, thanx to a fire call (I'm a firefighter).
#!/usr/bin/perl #INCLUDE LIBRARIES AND MODULES AS NEEDED #use strict; use CGI::Carp qw(fatalsToBrowser); use CGI; use DBI; #assign values $DBuser = "not"; $DBpass = "telling"; $DBtable= "the"; $DBhost = "world"; #connect to Database $dbh = DBI->connect("DBI:mysql:$DBtable:$DBhost", "$DBuser", "$DBpass" +, { PrintError => 0, RaiseError => 1 } ) || die "Error connecting: $D +BI::errstr!"; print "Content-type: text/html\n\n"; #grab files into @files opendir(DIR,"/home/kyleyankan/public_html/content/") || die "Can' open + dir: $!"; @files = readdir(DIR); close(DIR); #@files = glob("../public_html/content/*.inc"); #run loop, to transfer each file while (@files) { #print filename print $_ . "\n"; #grab file contents open(FILE,"/home/kyleyankan/public_html/content/$_"); @content = <FILE>; close(FILE); while (@content) { $stuff .= $_; } #remove .inc from file $_ =~ s/.inc//; #dump into DB $sth = $dbh->prepare(qq~ INSERT INTO quadrants (title, author, content) VALUES ("$_","KyleYankan","$stuff")~) || die "Can't insert values: $!"; $sth->execute || die "Can't insert values: $!"; } #leave that mysql alone $dbh->disconnect();