in reply to Why no $@ after eval? Bug?

Some short toying around results in these two short examples that yield no error/warning on ActiveState Perl 5.6.1 (Win32):

1>perl -we "sub rmap(&@){1}; eval { rmap { $_++ } 1 }; print $@;" 2>perl -we "sub rmap(&@){1}; rmap { $_++ } 1"

Replacing rmap with map yields the error you get in both cases:

3>perl -we "eval { map { $_++ } (1) }; print $@;" Modification of a read-only value attempted at -e line 1. 4>perl -we " map { $_++ } (1) " Modification of a read-only value attempted at -e line 1.

But I don't see why my cases 1 and 2 do not raise the error you want.

Update: Of course, ysth is correct, but with my modified variant (5 and 6, replacing 1 and 2), I get the error in both cases, as expected

5>perl -we "sub rmap(&@){my $c=shift;$c->($_) for @_}; rmap { $ +_++ } 1 print $@;" syntax error at -e line 1, near "1 print" Execution of -e aborted due to compilation errors. 6>perl -we "sub rmap(&@){my $c=shift;$c->($_) for @_}; rmap { $ +_++ } 1; print $@;" Modification of a read-only value attempted at -e line 1.

So maybe your special rmap doesn't call the callback in all cases?

Replies are listed 'Best First'.
Re: Re: Why no $@ after eval? Bug?
by ysth (Canon) on May 07, 2004 at 09:00 UTC
    Because your sub rmap doesn't actually call the coderef passed to it, so the increment is never actually done?