Matching { } braces ???

Discussion in 'Perl Misc' started by Rodney, Sep 13, 2003.

  1. Rodney

    Rodney Guest

    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,
    --
    ....
    `·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
    Rodney, Sep 13, 2003
    #1
    1. Advertising

  2. Rodney

    Rodney Guest

    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,

    --
    ....
    `·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
    Rodney, Sep 13, 2003
    #2
    1. Advertising

  3. Rodney

    Bob Walton Guest

    Rodney wrote:

    > 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.

    --
    Bob Walton
    Bob Walton, Sep 13, 2003
    #3
  4. On Fri, 12 Sep 2003 21:45:32 -0400
    "Rodney" <> wrote:

    > 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
    James Willmore, Sep 13, 2003
    #4
  5. Bob Walton <> wrote in
    news::

    > ... There is a saying that
    > "only Perl can parse Perl".


    Actually, the saying is "Only perl can parse Perl." Subtle difference.

    --
    Eric
    $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    ts p , map $ _. $ " , qw e p h tona e and print
    Eric J. Roode, Sep 13, 2003
    #5
  6. James Willmore <> wrote:

    > 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.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Sep 13, 2003
    #6
  7. On Sat, 13 Sep 2003 09:28:07 -0500
    (Tad McClellan) wrote:
    > James Willmore <> wrote:
    >
    > > 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.


    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.
    James Willmore, Sep 13, 2003
    #7
  8. Rodney

    Rodney Guest

    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.
    --
    ....
    `·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney
    Rodney, Sep 13, 2003
    #8
    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. Dustin D.
    Replies:
    0
    Views:
    2,303
    Dustin D.
    Aug 27, 2003
  2. bric

    brackets, braces and arrays

    bric, Jul 5, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    481
  3. Henrik S. Hansen

    Why braces around try/catch?

    Henrik S. Hansen, Aug 6, 2003, in forum: Java
    Replies:
    52
    Views:
    1,705
    Dale King
    Aug 22, 2003
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    233
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    226
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page