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

I am working on a sub and I keep getting this error during compilation: getrotatorform.cgi: Can't find string terminator "'" anywhere before EOF at functions.pl line 1029. Compilation failed in require at getrotatorform.cgi line 16. Could someone take a look? here's the sub:
sub dochangerotatorurls { $sth=runSQL("SELECT rurl2,rurl3,rurl4,rurl5,rurl6,rurl7 FROM rotator W +HERE userid='$login'"); ($oldrurl2,$oldrurl3,$oldrurl4,$oldrurl5,$oldrurl6,$oldrurl7)=$sth- +>fetchrow; @oldrurl=('$oldrurl2', '$oldrurl3', '$oldrurl4', '$oldrurl5', '$ol +drurl6', '$oldrurl7'); $url2=$q->param('rurl2'); $url3=$q->param('rurl3'); $url4=$q->param('rurl4'); $url5=$q->param('rurl5'); $url6=$q->param('rurl6'); $url7=$q->param('rurl7'); @url=('$url2', '$url3', '$url4', '$url5', '$url6', '$url7); foreach $url (@url) { foreach $oldrurl (@oldrurl) { if ($url ne $oldurl) { # if (($url eq '') || ($url eq 'http://')) {error("Enter url");} if (!($url=~/^http:/)) {$url="http://$url";} $qurl=$dbh->quote($url); $verify_url=$url; $verify_url=~s/^.*?\/\/(.*?)[:\/].*$/$1/; $verify_url=lc $verify_url; $sth=runSQL("SELECT COUNT(*) FROM blocksites WHERE name='$verify_ +url'"); ($num)=$sth->fetchrow; error("blockeddata") if $num; } else {@qurl=$dbh->quote(@oldrurl);} } } runSQL("UPDATE rotator SET rurl2=$qurl[0] rurl3=$qurl[1] rurl4=$qur +l[2] rurl5=$qurl[3] rurl6=$qurl[4] rurl7=$qurl[5] WHERE userid='$log +in'"); messagecp("Site rotator urls updated"); } 1;
line 1029 is the last runSQL update...yes, learning thanks

Replies are listed 'Best First'.
Re: string terminator "'"
by gjb (Vicar) on Jan 21, 2003 at 08:10 UTC
    @url=('$url2', '$url3', '$url4', '$url5', '$url6', '$url7);
    lacks a closing single quote around $url7

    To find such errors, comment out regions of code until found.

    Incidently, are you sure you want to quote $url2 et al.? This means you get a list with literal '$url2', etc., not with the values of those variables.

    Hope this helps, -gjb-

Re: string terminator "'"
by demerphq (Chancellor) on Jan 21, 2003 at 13:02 UTC
    Get and install perltidy (available from CPAN). Tidy will tell you exactly which unmatched " or brace is causing problems. Other than that it can be helpful to move an
    __END__
    tag slowly up from the bottom of the script once the message goes away you know that the problem is somewhere after the end tag. Also try doing
    perl -c script.pl
    so that the code doesnt actually execute.

    --- demerphq
    my friends call me, usually because I'm late....

Re: string terminator "'"
by Gilimanjaro (Hermit) on Jan 21, 2003 at 10:36 UTC
    As many have pointed out, it is the missing ' on the last item in the @url line...

    The low-effort way to quote multiple values into an array would be:

    @url=qw($url2 $url3 $url4 $url5 $url6 $url7);
    This creates a list of the words using any number of whitespace characters as seperator.

    But looking at your code I am *very* sure you don't want these guys quoted, as you are comparing the values from @oldrurl with @url, which will never be the same. You'll definitely want to keep these unquoted.

    In fact, the lines at the top could be replaced merely by:

    @oldurl=$sth->fetchrow;

    That's a spacesaver... :) The other one would be instead of all the $url? assignments:

    @url = map {$q->param("rurl$_")} (2..7);

    Some other tips to help you streamline your code;
    use strict; # yes, it'll scare your at first, but it's worth it.
    use DBI; # and it's placeholders for your selects and updates instead of interpolating.
    use vi! or some other syntax-coloring editor. That would've helped catching the runaway quote...

    Happy coding!

Re: string terminator "'"
by hotshot (Prior) on Jan 21, 2003 at 08:11 UTC
    you missed a quote in the following row:
    @url=('$url2', '$url3', '$url4', '$url5', '$url6', '$url7); # missin +g quote after $url7
    fixed that and see if your problem is fixed

    Hotshot