Matching { } braces ???

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Matching { } braces ???

    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 Guest

  2. Similar Questions and Discussions

    1. Contribute is converting curly braces upon editing
      The HTML has a meta tag inside which looks like this: {text here}. Upon opening the page in Contribute, the data is changed internally to %7btext...
    2. WebMethod works fine until it hits the closing braces - throws System.StackOverflowException
      Hi, I am getting System.StackOverflowException when calling a web method. The web method executes fine until it hits the closing braces that is...
    3. #22592 [Opn->Csd]: Cascading assignments to strings with curly braces broken
      ID: 22592 Updated by: sniper@php.net Reported By: matteo at beccati dot com -Status: Open +Status: ...
    4. #22592 [Csd->Opn]: Cascading assignments to strings with curly braces broken
      ID: 22592 Updated by: helly@php.net Reported By: matteo at beccati dot com -Status: Closed +Status: ...
    5. unicode in Image::Magick (hex values and braces problem?)
      Eric Schwartz <emschwar@pobox.com> wrote in comp.lang.perl.misc: To mimic the OP's code perfectly it should only use every other character. Note...
  3. #2

    Default Re: Matching { } braces ???

    Rodney wrote:

    (snipped)
    > 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?

    C:\APACHE\USERS\TEST>perl -c test.pl
    test.pl syntax OK


    Purl Gurl
    --
    Kick Ass Perl Programming: [url]http://www.purlgurl.net[/url]
    Purl Gurl Guest

  4. #3

    Default Re: Matching { } braces ???

    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 Guest

  5. #4

    Default Re: Matching { } braces ???

    Rodney wrote:
    > Purl,
    (snipped)
    > 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.

    You are using the wrong colors for highlighting.
    Try softer more feminine colors if you want
    something to work right.


    Purl Gurl
    --
    Most Intelligent Android To Be Found,
    Roberta The Remarkable Robot.
    [url]http://www.purlgurl.net/~callgirl/roberta/roberta.cgi[/url]
    Godzilla Guest

  6. #5

    Default Re: Matching { } braces ???

    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 Guest

  7. #6

    Default Re: Matching { } braces ???

    On Fri, 12 Sep 2003 21:45:32 -0400
    "Rodney" <NoSpamPlease@bellsouth.net> 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. [url]http://www.gnu.org/licenses/gpl.txt[/url]
    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 Guest

  8. #7

    Default Re: Matching { } braces ???

    Bob Walton <bwalton@rochester.rr.com> wrote in
    news:3F62A4D4.30607@rochester.rr.com:
    > ... 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 Guest

  9. #8

    Default Re: Matching { } braces ???

    James Willmore <jwillmore@cyberia.com> 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
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  10. #9

    Default Re: Matching { } braces ???

    On Sat, 13 Sep 2003 09:28:07 -0500
    [email]tadmc@augustmail.com[/email] (Tad McClellan) wrote:
    > James Willmore <jwillmore@cyberia.com> 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. [url]http://www.gnu.org/licenses/gpl.txt[/url]
    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 Guest

  11. #10

    Default Re: Matching { } braces ???

    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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139