BEGIN not safe after errors--compilation aborted

Discussion in 'Perl Misc' started by daz9643, Feb 22, 2008.

  1. daz9643

    daz9643 Guest

    I've got 2 perl scripts, both are code for ads. One script is admob,
    the other is google. The code provided has been cut and pasted without
    any mods. The admob code works, the google code doesn't and i get the
    error,
    syntax error at googleperlcode.cgi line 9, near "sub
    google_append_color "
    Can't use global @_ in "my" at googleperlcode.cgi line 10, near ", $_"
    syntax error at googleperlcode.cgi line 12, near "}"
    Execution of googleperlcode.cgi aborted due to compilation errors.

    This is the actual google code,
    #!/usr/bin/perl
    use CGI::Carp qw(fatalsToBrowser);
    ul class="simpleblue"
    sub google_append_color {
    my @color_array = split(/,/, $_[0]);
    return $color_array[$_[1] % @color_array];
    }

    Anyone know why the errors ? Both files end in .cgi and both have the
    permissions set the same, i.e 755. Both are in the same directory on
    the server.
    daz9643, Feb 22, 2008
    #1
    1. Advertising

  2. daz9643

    J. Gleixner Guest

    daz9643 wrote:
    > I've got 2 perl scripts, both are code for ads. One script is admob,
    > the other is google. The code provided has been cut and pasted without
    > any mods. The admob code works, the google code doesn't and i get the
    > error,
    > syntax error at googleperlcode.cgi line 9, near "sub
    > google_append_color "
    > Can't use global @_ in "my" at googleperlcode.cgi line 10, near ", $_"
    > syntax error at googleperlcode.cgi line 12, near "}"
    > Execution of googleperlcode.cgi aborted due to compilation errors.
    >
    > This is the actual google code,
    > #!/usr/bin/perl
    > use CGI::Carp qw(fatalsToBrowser);
    > ul class="simpleblue"

    ^^^^^^^^^^^^^^^^^^^^^^
    Does that look at all like it's valid syntax?

    > sub google_append_color {
    > my @color_array = split(/,/, $_[0]);
    > return $color_array[$_[1] % @color_array];
    > }
    >
    > Anyone know why the errors ? Both files end in .cgi and both have the
    > permissions set the same, i.e 755. Both are in the same directory on
    > the server.
    J. Gleixner, Feb 22, 2008
    #2
    1. Advertising

  3. daz9643 <> wrote:


    > syntax error at googleperlcode.cgi line 9, near "sub

    ^^^^^^
    ^^^^^^
    > This is the actual google code,



    I do not believe you.


    > #!/usr/bin/perl
    > use CGI::Carp qw(fatalsToBrowser);
    > ul class="simpleblue"
    > sub google_append_color {
    > my @color_array = split(/,/, $_[0]);
    > return $color_array[$_[1] % @color_array];
    > }



    There is no line 9 in your 7 line program...


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Feb 23, 2008
    #3
  4. daz9643

    daz9643 Guest

    ok ,the actual google code does not include the lines
    use CGI::Carp qw(fatalsToBrowser);
    ul class="simpleblue"

    these to lines were just added to help with debugging. Without these 2
    lines i just get the error 500.
    You're right about line 9, there were a few blank lines in the code
    which i've deleted as they weren't necessary. If i remove the
    offending line of code or rem it out the error just points to the next
    line of code and so on.
    daz9643, Feb 23, 2008
    #4
  5. daz9643

    Ron Bergin Guest

    On Feb 23, 10:17 am, daz9643 <>
    wrote:
    > ok ,the actual google code does not include the lines
    > use CGI::Carp qw(fatalsToBrowser);
    > ul class="simpleblue"
    >
    > these to lines were just added to help with debugging. Without these 2
    > lines i just get the error 500.
    > You're right about line 9, there were a few blank lines in the code
    > which i've deleted as they weren't necessary. If i remove the
    > offending line of code or rem it out the error just points to the next
    > line of code and so on.


    Well, it's pretty obvious that this line:

    > ul class="simpleblue"


    will generate an error.

    Comment out that line and retest. If if fails, then post the exact
    error message and the EXACT code that you tested, but only upto a
    couple lines after the reported line in the error messages.
    Ron Bergin, Feb 23, 2008
    #5
  6. daz9643

    daz9643 Guest

    With ul class="simpleblue" removed all i get is,


    Internal Server Error
    The server encountered an internal error or misconfiguration and was
    unable to complete your request.
    Please contact the server administrator,
    and inform them of the time the
    error occurred, and anything you might have done that may have caused
    the error.

    More information about this error may be available in the server error
    log.


    #!/usr/bin/perl
    use CGI::Carp qw(fatalsToBrowser);
    use LWP::UserAgent;
    use Time::HiRes qw(gettimeofday);
    use URI::Escape;
    daz9643, Feb 25, 2008
    #6
  7. daz9643

    daz9643 Guest

    This is what i've tried to follow to sort the problem, cut & pasted
    from 123-reg.co.uk online support,

    <p>If you encounter an error "500 Internal Server Error" whilst
    running your CGI perl scripts, try the following in order:</p>

    <ul class="simpleblue">
    <li>Ensure you have uploaded the script through FTP using ASCII mode,
    or that it has Unix-style carriage returns.</li>
    <li>Check the perl interpreter on the first line of the script. It
    should always be "#!/usr/bin/perl".</li>
    <li>Make sure the script filename ends in either ".pl" or ".cgi".</li>
    <li>Make sure the script can execute. It should have mode "0755". You
    can change this in your file manager - set the mode to user read+write
    +execute, group read+execute, other read+execute. Most FTP clients
    also support this.</li>
    <li>Put "use CGI::Carp qw(fatalsToBrowser);" into the second line of
    your script. This will make perl print the error instead of the "500
    Internal Server Error" page, and will allow you to find out where your
    script is breaking.</li>
    </ul>
    daz9643, Feb 25, 2008
    #7
  8. daz9643

    Dave Weaver Guest

    daz9643 <> wrote:
    > This is what i've tried to follow to sort the problem, cut & pasted
    > from 123-reg.co.uk online support,
    >
    > <li>Put "use CGI::Carp qw(fatalsToBrowser);" into the second line of
    > your script. This will make perl print the error instead of the "500
    > Internal Server Error" page, and will allow you to find out where your
    > script is breaking.</li>
    > </ul>


    So it tells you to add "use CGI::Carp qw(fatalsToBrowser);"

    Where did the 'ul class="simpleblue"' come from? This is not valid perl code.

    Also, your initial program:

    #!/usr/bin/perl
    sub google_append_color {
    my @color_array = split(/,/, $_[0]);
    return $color_array[$_[1] % @color_array];
    }

    is no good as a stand-alone CGI script, which is what you appear to be using it
    as. The web server is expecting some output from your CGI script, yet it does
    nothing. Hence the "500 Internal server error".

    It is not clear what you are tying to acheive.
    Dave Weaver, Feb 26, 2008
    #8
  9. daz9643

    daz9643 Guest

    Hi Dave, all i want to do is put google ads on my mobile website. The
    code options given by Google are PHP which my host does not support,
    CGI/Perl, JSP and ASP. My site is written in XHTML and is saved as
    a .shtml file. I thought the simplest solution would be to copy the
    Google Perl ad code and save it as a .cgi file. The place where i want
    the ads to appear executes the Perl file using this line of code,

    <!--#exec cgi="/cgi-bin/googleperlcode.cgi" --><br />

    I've done exactly the same thing using ad code from Admob so i can't
    understand why this doesn't work as as i know nothing about Perl i've
    come to a dead end.

    The entire Google ad code is below,
    #!/usr/bin/perl

    use LWP::UserAgent;
    use Time::HiRes qw(gettimeofday);
    use URI::Escape;

    sub google_append_color {
    my @color_array = split(/,/, $_[0]);
    return $color_array[$_[1] % @color_array];
    }

    sub google_append_screen_res {
    my $screen_res = $ENV{"HTTP_UA_PIXELS"};
    my $delimiter = "x";
    if ($screen_res == "") {
    $screen_res = $ENV{"HTTP_X_UP_DEVCAP_SCREENPIXELS"};
    $delimiter = ",";
    }
    my @res_array = split($delimiter, $screen_res);
    if (@res_array == 2) {
    return "&u_w=" . $res_array[0] . "&u_h=" . $res_array[1];
    }
    }

    my $google_dt = sprintf("%.0f", 1000 * gettimeofday());
    my $google_scheme = ($ENV{"HTTPS"} eq "on") ? "https://" : "http://";
    my $google_host = uri_escape($google_scheme . $ENV{"HTTP_HOST"});

    my $google_ad_url = "http://pagead2.googlesyndication.com/pagead/
    ads?" .
    "ad_type=text" .
    "&channel=" .
    "&client=ca-mb-pub-5303496068311064" .
    "&dt=" . $google_dt .
    "&format=mobile_single" .
    "&host=" . $google_host .
    "&ip=" . uri_escape($ENV{"REMOTE_ADDR"}) .
    "&markup=xhtml" .
    "&oe=utf8" .
    "&output=xhtml" .
    "&ref=" . uri_escape($ENV{"HTTP_REFERER"}) .
    "&url=" . $google_host . uri_escape($ENV{"REQUEST_URI"}) .
    "&useragent=" . uri_escape($ENV{"HTTP_USER_AGENT"}) .
    google_append_screen_res();

    my $google_ua = LWP::UserAgent->new;
    my $google_ad_output = $google_ua->get($google_ad_url);
    if ($google_ad_output->is_success) {
    print $google_ad_output->content;
    }
    daz9643, Feb 26, 2008
    #9
  10. daz9643

    Dave Weaver Guest

    > my $google_ua = LWP::UserAgent->new;
    > my $google_ad_output = $google_ua->get($google_ad_url);
    > if ($google_ad_output->is_success) {
    > print $google_ad_output->content;
    > }



    If the get() call fails, your program outputs nothing, and
    you will get a "500 internal server error", or similar.

    Change that to:

    if ($google_ad_output->is_success) {
    print $google_ad_output->content;
    }
    else {
    print "failed to fetch ad:\n"
    . "URL = $google_ad_url\n"
    . "status = " . $google_ad_output->status_line
    . "\n";
    }

    Then run the script by hand from a command prompt:
    perl googleperlcode.cgi

    to see what output you get. I suspect there is a problem
    fetching whatever URL it builds.
    Dave Weaver, Feb 27, 2008
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S2VpdGggRi4=?=

    Thread was being aborted errors

    =?Utf-8?B?S2VpdGggRi4=?=, Jan 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,947
    Alvin Bruney [MVP]
    Jan 10, 2005
  2. =?Utf-8?B?S2VpdGggRi4=?=

    Thread was being aborted errors

    =?Utf-8?B?S2VpdGggRi4=?=, Jan 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    424
    =?Utf-8?B?S2VpdGggRi4=?=
    Jan 10, 2005
  3. =?Utf-8?B?S2VpdGggRi4=?=

    Thread was being aborted. Errors

    =?Utf-8?B?S2VpdGggRi4=?=, Jan 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,069
    Hans Kesting
    Jan 10, 2005
  4. Gabriel Rossetti
    Replies:
    0
    Views:
    1,297
    Gabriel Rossetti
    Aug 29, 2008
  5. peppermonkey
    Replies:
    1
    Views:
    227
    Gregory Brown
    Feb 10, 2007
Loading...

Share This Page