in reply to Re: Re: Syntax error with if following eval
in thread Syntax error with if following eval

Actually, I have been looking up why what you did was an error.

If you think about a string eval, the problem would have been clearer, I think:

eval '1' if (1) {}

but if you would write the block eval as:

eval { 1 } if (1) { }

then it becomes very confusing and unclear why that would be a problem. I guess it's just one of the Perl's syntaxical quirks that you need to get used to.

Liz

Replies are listed 'Best First'.
Re: Re: Re: Re: Syntax error with if following eval
by simonm (Vicar) on Sep 09, 2003 at 03:31 UTC
    For what it's worth, I believe that the language design for Perl 6 specifies that the trailing semicolon after an eval block will become optional.
Re: Re: Re: Re: Syntax error with if following eval
by benizi (Hermit) on Sep 09, 2003 at 19:21 UTC
    I think the problem is that the if is seen as a modifier to the eval statement, after which point the {} mucks up the parsing.

    You'd get the same error from: print "hahaha\n" if (1) {};

    So, in the eval case, perl thinks you want: eval { 1 } if ($@); but finds an extra block.

Re: Re: Re: Re: Syntax error with if following eval
by Anonymous Monk on Sep 09, 2003 at 00:04 UTC

    Thank you: I was trying to figure out why it was wrong myself. It didn't seem so very wrong, because I always associate {} with "code blocks" that don't require trailing ;'s. When you put it in terms of the string eval that makes it a lot clearer.