Matching { } braces ???

R

Rodney

In the example below, I'm testing if a string contains either the { or }
braces. The problem is that it is causing me a syntax error. The { on the
end of line #1 is pairing with the } on line #11 that is within the
=~m/\}/ pattern search.

Can anyone explain how to avoid this?

-------------------------------------------------------
#1 if ($bodytest_line =~ m/\{/) {
#2 $StartBraceComment = 1;
#3 $bodyTextLen = length($bodytest_line);
#4 $bodyLineCommentStartPos = index($bodytest_line, "{");
#5 $bodyLineCommentText = substr($bodytest_line,
$bodyLineCommentStartPos, $bodyTextLen);
#6 $bodyLineCommentText = "<I><Font
COLOR=$CommentColor>$bodyLineCommentText";
#7 $bodyLineNotCommentText = substr($bodytest_line, 0,
$bodyLineCommentStartPos);
#8 $bodyLineNotCommentText =
&OpalKeywords($bodyLineNotCommentText);
#9 $bodyLineNotCommentText =
&OpalQuotedText($bodyLineNotCommentText);
#10
#11 if ($bodyLineCommentText =~ m/\}/) {
#12 $bodyLineCommentText2Len = length($bodyLineCommentText);
#13 $bodyLineCommentEndPos2 = index($bodyLineCommentText,
"}");
#14 $bodyLineCommentText2 = substr($bodyLineCommentText,
0, $bodyLineCommentEndPos2);
#15 $bodyLineCommentText2 =
"$bodyLineCommentText</FONT></I>";
#16 $StartBraceComment = 0;
#17 }
#18 }



Thanks,
 
R

Rodney

Purl,

I'm editing using conTEXT... It has a PERL syntax highlighter built in.
When I paste the code I included ( as an example in the last post ) into
conTEXT and highlight one of the braces... it is suppose to show me the
matching brace by highlighting it too. This code is throwing it off.

Also... this code is part of a larger code write. The problem started when
I added the search for the { } braces. Now my error code tells me:

"Missing right curly or square bracket at
/u/web/XXXXXX/cgi-local/OPALconvert.pl line 485, at end of line
syntax error at /u/web/XXXXXXXX/cgi-local/OPALconvert.pl line 485, at EOF
/u/web/XXXXXXXX/cgi-local/OPALconvert.pl had compilation errors."


Note: line 485 is the last line. This indicates to me that the problem is
associated with the Braces.

Any help would be appreciated.
Thanks,
 
B

Bob Walton

Rodney said:
Purl,

I'm editing using conTEXT... It has a PERL syntax highlighter built in.
When I paste the code I included ( as an example in the last post ) into
conTEXT and highlight one of the braces... it is suppose to show me the
matching brace by highlighting it too. This code is throwing it off.

Also... this code is part of a larger code write. The problem started when
I added the search for the { } braces. Now my error code tells me:

"Missing right curly or square bracket at
/u/web/XXXXXX/cgi-local/OPALconvert.pl line 485, at end of line
syntax error at /u/web/XXXXXXXX/cgi-local/OPALconvert.pl line 485, at EOF
/u/web/XXXXXXXX/cgi-local/OPALconvert.pl had compilation errors."


Note: line 485 is the last line. This indicates to me that the problem is
associated with the Braces.


....


Perl thinks your code as posted is fine (as regards compilation -- I
made no attempt to run it). Note that just because your editor's syntax
highlighting or brace searching screwed up doesn't necessarily mean
there is anything wrong with your code. There is a saying that "only
Perl can parse Perl".

Here is a simple piece of standalone code which illustrates the same
problem and also shows that Perl parses, compiles and executes it fine:

$_="{}";
if(/{/){
print "1match\n";
if(/}/){
print "2match\n";
}
}

If it is any consolation, VIM's color syntax highlighting highlights
correctly, but its brace-matching ability suffers the same problem your
editor has.

Regarding the problem with your larger piece of code, I suggest you look
in it rather than the piece you posted, as the problem is probably
somewhere in the other code. You can check brace matching by snipping
pieces out and running perl -c on them.
 
J

James Willmore

In the example below, I'm testing if a string contains either the {
or } braces. The problem is that it is causing me a syntax error.
The { on the end of line #1 is pairing with the } on line #11
that is within the=~m/\}/ pattern search.

Can anyone explain how to avoid this?
<snip>

Read ...
perldoc perlstyle

It works not just for Perl, but other languages as well (such as bash,
C++, Java, PHP, or, dare I say, C-shell).

I read your other post about using an IDE for Perl. Maybe you need to
configure it to fall in line with the accepted style that Perl has put
forth. More importantly, have you tried to edit the script in
something other than an IDE, applying what you applied from the style
guide?

And, as Purl Gurl suggested, run with the script with syntax checking:
perl -c <script name here>

The number one error that crops up in programming is the dreded syntax
error. The style guide will assist you in mimimizing the number you
encounter.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
In seeking the unattainable, simplicity only gets in the way.
-- Epigrams in Programming, ACM SIGPLAN Sept. 1982
 
T

Tad McClellan

James Willmore said:
The number one error that crops up in programming is the dreded syntax
error.


In the universe of all potential programmer's errors, a
"syntax error" is the *most welcome* of all possible errors!

Because they are the easiest to find. So easy that even a
machine can find them.

It is those pesky "semantic errors" that are dreaded.
 
J

James Willmore

The number one error that crops up in programming is the dreded
syntax error.


In the universe of all potential programmer's errors, a
"syntax error" is the *most welcome* of all possible errors!

Because they are the easiest to find. So easy that even a
machine can find them.

It is those pesky "semantic errors" that are dreaded.[/QUOTE]

True. I sit corrected - too lazy to stand ;)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
It wasn't that she had a rose in her teeth, exactly. It was more
like the rose and the teeth were in the same glass.
 
R

Rodney

Thanks all.

I found the problem. It was a faulty set of braces that "I" did... not a
PERL issue.

I made the mistake of writing a lot of code without testing it as I went
along. I was starting to get that "this will never work" feeling.... but I
couldn't stop writing because I had to get the code out of my head.

As I suspected.... deep in the bowels of that code was errant syntax.

I ended up having to REM out everything... then add it back in... 1 piece at
a time, until it blew up.

I lesson I "thought" I learned several times before. :(

Thanks again for your help.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top