# Use strict and warnings. This is not optional especially when asking # for help. use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); # Import some defaults use CGI qw/:standard/; # Explictly prevent any imports since we don't need them. use DBI (); # Slurp all files undef $/; # Put the configuration data right up at the top so you # aren't putting it into your script. use constant DB_HOSTNAME => 'not'; use constant DB_USERNAME => 'telling'; use constant DB_PASSWORD => 'the'; use constant DB_TABLE => 'word'; use constant INC_DIR => "/home/kyleyankan/public_html/content/"; # To format is divine. Just do it. $dbh = DBI -> connect( "DBI:mysql:" . DB_TABLE . ':' . DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, { PrintError => 0, RaiseError => 1 }, ) or die "Error connecting: $DBI::errstr!"; # Don't do HTML when you can have CGI create it for you # (and it comes out nice too) print header(), html_header(); # Read all of the '*.inc' files from the specified # directory my @inc_files = glob INC_DIR . "*.inc"; # This was your infinite loop. You used while when you should # have used for(). for my $filename ( @inc_files ) { print $filename, br; # You didn't check for failure here. A no-no. Also # since I unset $/ the file will be slurped in one shot. # Also, your use of the handle is distressing. First you # read the entire thing into an array. Next you read each # element (after you switch while() for for()) and # concatenate to the $stuff variable (which you didn't # remember to use my() on so it # And during writing these comments I got distracted and # upgraded a server. Guess I'll just post these. open FILE, INC_DIR . $filename or die "Couldn't close $filename: $!"; my $file_contents = ; close FILE or die "Couldn't close $filename: $!"; # remove .inc from the filename. Originally you wrote # $_ =~ s/.../.../ and that's just redundant. Either you # specify the variable because it's not $_ or just let # the operator take the default. $filename =~ s/\.inc$//; # insert into the database. # 1) add formatting. # 2) remove the 'or die' lines because you already had RaiseError set for the connection # 3) use place holders # 4) Don't abuse the use of "$variable", ... $dbh -> do( "INSERT INTO quadrants ( title, author, content ) VALUES ( ?, ?, ? )", undef, $filename, "KyleYankan", $file_contents); } #leave that mysql alone $dbh->disconnect();