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

I guess I am doing somehthing wrong, but I can't find what.

When compiling this code with Perl version 5.8.8:

$ cat Prueba3.pm BEGIN { unless (Parse::Eyapp::Driver->can('YYParse')) { eval q{ package Parse::Eyapp::Driver; require 5.006; #sub _DBLoad { 1; }; # End of string containing Parse::Eyapp::Driver }; # Unless Parse::Eyapp::Driver was loaded } ########### End of BEGIN
it gives me an error:
$ perl -c Prueba3.pm Missing right curly or square bracket at Prueba3.pm line 16, at end of + line (Might be a runaway multi-line {} string starting on line 3) syntax error at Prueba3.pm line 16, at EOF Prueba3.pm had compilation errors. $ perl -v This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
If I delete the comment there are no errors:
pl@nereida:/tmp$ diff Prueba3.pm Prueba.pm 9d8 < #sub _DBLoad { pl@nereida:/tmp$ perl -c Prueba.pm Prueba.pm syntax OK
Can someone help?

Thanks

Casiano

UPDATE:

I have got the same behavior when using Perl 5.10.0

casiano@beowulf:~$ perl -v This is perl, v5.10.0 built for i486-linux-gnu-thread-multi casiano@beowulf:~$ perl -c Prueba3.pm Missing right curly or square bracket at Prueba3.pm line 16, at end of line (Might be a runaway multi-line {} string starting on li +ne 3) syntax error at Prueba3.pm line 16, at EOF Prueba3.pm had compilation errors. casiano@beowulf:~$ perl -c Prueba.pm Prueba.pm syntax OK casiano@beowulf:~$ cat -n Prueba.pm 1 BEGIN { 2 unless (Parse::Eyapp::Driver->can('YYParse')) { 3 eval q{ 4 5 package Parse::Eyapp::Driver; 6 7 require 5.006; 8 9 10 1; 11 12 13 }; # End of string containing Parse::Eyapp::Driver 14 }; # Unless Parse::Eyapp::Driver was loaded 15 } ########### End of BEGIN casiano@beowulf:~$ cat -n Prueba3.pm 1 BEGIN { 2 unless (Parse::Eyapp::Driver->can('YYParse')) { 3 eval q{ 4 5 package Parse::Eyapp::Driver; 6 7 require 5.006; 8 9 #sub _DBLoad { 10 11 1; 12 13 14 }; # End of string containing Parse::Eyapp::Driver 15 }; # Unless Parse::Eyapp::Driver was loaded 16 } ########### End of BEGIN

Of course, the problem can be "solved" by inserting a false "}" inside a comment:

$ perl -c Prueba3trick.pm Prueba3trick.pm syntax OK pl@nereida:/tmp$ cat -n Prueba3trick.pm 1 BEGIN { 2 unless (Parse::Eyapp::Driver->can('YYParse')) { 3 eval q{ 4 5 package Parse::Eyapp::Driver; 6 7 require 5.006; 8 9 #sub _DBLoad { # False curly: } 10 11 1; 12 13 14 }; # End of string 15 }; # Unless Parse::Eyapp::Driver was loaded 16 } ########### End of BEGIN

Replies are listed 'Best First'.
Re: Perl 5.8.8 bug?
by Corion (Patriarch) on Oct 16, 2008 at 10:26 UTC

    See Quote and Quote like Operators, especially the note about using curlies and "Note, however, that this does not always work for quoting Perl code". Use a real here-doc to quote your Perl code instead of hoping that the string will only ever contain a balanced set of brackets:

    eval <<'END_OF_CODE'; package ... 1; END_OF_CODE
Re: Perl 5.8.8 bug?
by ikegami (Patriarch) on Oct 16, 2008 at 14:02 UTC

    Of course, the problem can be "solved" by inserting a false "}" inside a comment:

    A simpler solution would have been to escape the delimiter like you would do with single-line string literals.

    #sub _DBLoad \{

    However, single-quoted here-docs are even simpler. They remove the need to escape slashes and delimiters.

    eval <<'__EOI__'; ... __EOI__

    For example, the output of the following two snippets differ only in the leading newline.

    print q{ foo \{ \} \\\\ bar };
    print <<'__EOI__'; foo { } \\ bar __EOI__

    Update: Added escaping solution.

Re: Perl 5.8.8 bug?
by Anonymous Monk on Oct 16, 2008 at 12:54 UTC