I know this is not a cpanel issue, but does anyone see anyting wrong with this script

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
Sorry to post this here, but this little script has been giving me a headache for like 4 hours.

I keep getting a premature end of script headers on this file. It is chmod to 755, but still gives me the error:

PHP:
#!/usr/bin/perl
use strict;

open FILE, "<BF41.MS" or die "$!\n";
chomp(my @a=<FILE>) or die "$!\n";
close FILE;

my @b = ();

foreach (@a) {
  $_ =~ s/"//gs;
  my ($a, $b, $c, $d) = split /\|/, $_;  
  $a =~ s/\\/\\\\/gs; $a =~ s/'/\\'/gs;
  $b =~ s/\\/\\\\/gs; $b =~ s/'/\\'/gs;
  $c =~ s/\\/\\\\/gs; $c =~ s/'/\\'/gs;
  $d =~ s/\\/\\\\/gs; $d =~ s/'/\\'/gs;

  push @b, qq|insert into allparts (part_number, description, price, weight) values ('$a', '$b', '$c', '$d');|;
}
open FILE, ">allparts.sql" or die "$!\n";
foreach (@b) { print FILE "$_\n"; }
close FILE;
I've made sure to upload it in ascii format, and removed any whitespaces, but still it doesn't work.

If it's not the script, what else could it be?

Thanks!
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
33
473
Go on, have a guess
You're missing a couple of backslashes in the final statements:
Code:
open FILE, ">allparts.sql" or die "$![B]\[/B]n";
foreach (@b) { print FILE "$_[B]\[/B]n"; }
close FILE;
Also, if you're running this as a CGI script, you will need some output to your browser, though not if it's a cron job. So putting something like the following at the bottom should suffice:
Code:
print "content-type: text/html\n\n";
print "Completed.\n";
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
You're missing a couple of backslashes in the final statements:
Code:
open FILE, ">allparts.sql" or die "$![B]\[/B]n";
foreach (@b) { print FILE "$_[B]\[/B]n"; }
close FILE;
Also, if you're running this as a CGI script, you will need some output to your browser, though not if it's a cron job. So putting something like the following at the bottom should suffice:
Code:
print "content-type: text/html\n\n";
print "Completed.\n";

Chirpy,

Thanks for the info. However, i think the forum stripped off those backslashes when I made the intial post, because they are in there..

So if the code looks ok, then it must be something on the server side....

Here's the code again...let's see if it doesn't strip anything this time:

#!/usr/bin/perl
use strict;

open FILE, "<BF41.MS" or die "$!\n";
chomp(my @a=<FILE>) or die "$!\n";
close FILE;

my @b = ();

foreach (@a) {
$_ =~ s/"//gs;
my ($a, $b, $c, $d) = split /\|/, $_;
$a =~ s/\\/\\\\/gs; $a =~ s/'/\\'/gs;
$b =~ s/\\/\\\\/gs; $b =~ s/'/\\'/gs;
$c =~ s/\\/\\\\/gs; $c =~ s/'/\\'/gs;
$d =~ s/\\/\\\\/gs; $d =~ s/'/\\'/gs;

push @b, qq|insert into allparts (part_number, description, price, weight) values ('$a', '$b', '$c', '$d');|;
}
open FILE, ">allparts.sql" or die "$!\n";
foreach (@b) { print FILE "$_\n"; }
close FILE;

print "content-type: text/html\n\n";
print "Completed.\n";
 
Last edited:

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
33
473
Go on, have a guess
It it is still failing, then it would suggest an error is being generated at run time. Try adding the following line after the first line:

use CGI::Carp qw(fatalsToBrowser);
 

noimad1

Well-Known Member
Mar 27, 2003
626
0
166
It it is still failing, then it would suggest an error is being generated at run time. Try adding the following line after the first line:

use CGI::Carp qw(fatalsToBrowser);


Hmm...that came up with "Bad file descriptor". I'm thinking that has to do with the file being opened?