The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'General Discussion' started by noimad1, May 29, 2007.

  1. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    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 @= ();

    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!
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    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";
     
  3. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16

    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:

     
    #3 noimad1, May 29, 2007
    Last edited: May 29, 2007
  4. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    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);
     
  5. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16


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

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Sounds like a coding error, or problems with the input/output files, rather than a syntax issue ;)
     
Loading...

Share This Page