Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't see why syntax error

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
US
I have two identical sections right above this section, only changes are variable names, both of those sections work just fine

Code:
print <<EOF
</select>
<select id="vendor_name_selected" name="vendor_name_selected">
<option value="All">All</option>
EOF

undef my $tbl6;
    undef my $statement5;
    $table = "products2";

    $statement5="SELECT DISTINCT vendor_name FROM $table;";
    my $sth5 = $dbh->prepare($statement5) || die $dbh->errstr;
    my $rc5  = $sth5->execute                      || die $dbh->errstr;
    
    while ($tbl6 = $sth5->fetchrow_arrayref)
    	{
print "<option value=\"@$tbl6\">@$tbl6</option>";
}

I am getting the following errors:
syntax error at /var/ line 840, near "F\n\nundef"
and
Global symbol "$table" requires explicit package name at /var/ line 842.

Adding a my to $table(not needed actually) just bumps problem to next variable down the line.

I've even moved all to another place and get same errors.

This has to be obvious, but I can't see the problem
 
Its not obvious, but these lines look wrong:

Code:
undef my $tbl6;
    undef my $statement5;

They should be:

Code:
undef $tbl6;
    undef $statement5;

although thats not going to help with $table. All I can say is make sure $table is declared with "my" within its proper scope.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I was right, absolutely obvious!!

Darn HERE documents! Love 'um and Hate 'um!

Code:
print <<EOF

OOPS! should be
Code:
print <<EOF;

What worthless error messages though!
Had me looking in all the wrong places for a simple solution!!

Actually found one wrong in another sub, but that one never crashed for some reason.
 
Thats why you shouldn't use heredocs, use a modern quoting operator like q or qq.

Code:
print q{
</select>
<select id="vendor_name_selected" name="vendor_name_selected">
<option value="All">All</option>
};

Use qq for double-quoted strings, q for single-quoted strings.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Darn HERE documents! Love 'um and Hate 'um!
No. I just hate them. They seem to be a hangover from shell scripting, but they are just ugly...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
I for one like heredocs, because they seem to be the only format that syntax highlighters fully understand (vim and gedit).

i.e. q{} and qq{} with curly brackets seem to be the only one understood at all (any other delimeter doesn't work), and then even when you do use the curly brackets, the first closing bracket stops the syntax highlighting even though you haven't closed the quote, e.g. q{ if(1) {...} else {...} };, and then the syntax highlighting is all messed up from that point on and ya need to put a bunch of odd symbols in a comment to fix it or else the entire rest of your code is ugly.

so +1 for heredocs.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
I use kate from KDE (just not IN kde anymore)

It's syntax highlighting gets messed up a lot
I found that
Code:
 if ($y) {
etc
really messes things up but that
Code:
 if ($y)
   {
etc
putting { on another line fixes code folding problem, for that case only.

I haven't tried putting symbols in a comment, though.
I will try that!

Any other pointers for fixing highlighting?
 
That's the only pointer I know of so far.

Code:
[blue]$hash[/blue]{expiration} =~ [teal]s![/teal][fuchsia]^[/fuchsia][red]..(..)[/red][fuchsia]-[/fuchsia][red](..).+[/red][blue]$!$2[/blue][fuchsia]/[/fuchsia][blue]$1[/blue][teal]![/teal][fuchsia];  #extract mm/yy -->[/fuchsia][teal]![/teal]<-- this fixes vim highlighting



Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
All highlighters have a problem or two with some syntax. Even my perl IDE has a problem or two trying to highlight perl code. Thats a reason I never heard before to support using one operator over another operator, because the syntax highlighting is better. But so be it.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top