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

I have a 600 line program that has no closing '}' for a loop. Perlcritic and perl -c report no problems and as far as I can see the program runs correctly. I am using shift % in vi to find matching brackets and it cannot find a match for the top-most loop...any ideas?

Replies are listed 'Best First'.
Re: no matching '}'
by Old_Gray_Bear (Bishop) on Feb 03, 2015 at 22:18 UTC
    My usual assault on the missing '}' problem:
    1. Run the original code through pertidy and save the result.
    2. Edit the code to add a "}' as the last line of the new code.
    3. perltidy again and save the result.
    4. Run diff between the two outputs.
    5. Resolve/explain the diffs
    It takes time,sorry but there is no Magic to sort it out.

    For what it's worth, the last time I had to dig out of a missing brace, it was because someone had decided to use '}' as the delimiter in a compound Regex in some code originating for the 5.0.x era (Thank you Red Hat). I was contracted to bring up to the 'current version of Perl' -- 5.8.0. Sigh. Thanks again Red Hat. At least it keeps me in quick contracts.

    ----
    I Go Back to Sleep, Now.

    OGB

Re: no matching '}'
by Eily (Monsignor) on Feb 03, 2015 at 17:15 UTC

    Have you tried to Deparse it? I see three way to have brackets that don't match: source filters, quote constructs that are not parsed properly (only perl can parse perl) or the use of the -p or -n switch with an obfuscation like the eskimo kiss.

      deparse reports syntax OK

        Ok but does it Deparse to the same thing? If this doesn't help, try removing bits of code until you get a minimal reproduction case that you can share.

Re: no matching '}'
by LanX (Saint) on Feb 03, 2015 at 17:05 UTC
    > any ideas

    Eval? Regex? Import?

    And you are hanging around here for a wile now, you should know that we'd like to see the error msg instead wasting time speculating.

    Cheers Rolf

    PS: Je suis Charlie!

      there are no error messages and no use of eval nor import. I am using regex's. I only found this by commenting on closing loops '}'. There is nothing indicating any error. I am loath to attach the code.
        I have trouble understanding what you are doing.

        Maybe try perltidy ...

        Cheers Rolf

        PS: Je suis Charlie!

Re: no matching '}'
by Anonymous Monk on Feb 03, 2015 at 23:01 UTC
    Vim-perl group suggests using matchit plugin. I can't post a link to github so search for 'vim-perl issue 86'.
      'deparse' fixes the problem but it removes all comments!! and deconstructs hash declarations and generally crams everything together.....but the '{' matching works OK and the program runs OK.
Re: no matching '}'
by locked_user sundialsvc4 (Abbot) on Feb 03, 2015 at 17:33 UTC

    use strict; use warnings; ... yes?

      yes....perlcritic, perltidy and 'perl -c' report that all is fine. using strict and warnings
        I'm just realizing that you are talking about a vi problem with your way of coding...

        Ahhhhhhhh!

        Cheers Rolf

        PS: Je suis Charlie!