"Exiting eval via next" [perl v5.14]
Dave Hodgkinson
davehodg at gmail.com
Mon Nov 7 12:08:54 GMT 2011
On 7 Nov 2011, at 11:55, Peter Haworth wrote:
> On Fri, 4 Nov 2011 21:49:49 +0000, Dave Hodgkinson wrote:
>> On 4 Nov 2011, at 20:16, Graham Barr wrote:
>>> On Nov 4, 2011, at 11:36 , Chisel wrote:
>>>>
>>>> # why no error?!
>>>> $ perl -M5.14.0 -wle 'for my $i (qw/foo/) { eval { $i.=q{}; next; }; } say
>>>> "done"'
>>>> done
>>>
>>> Because the next never happens, check $@ you will see
>>>
>>> Modification of a read-only value attempted
>>
>> A more enlightening error would be nice.
>>
>> I find myself tempted to next in the $@ check. What's a good
>> idiom for failing out of an eval then?
>
> Isn't that what die or return are for? Assuming that eval is the only thing
> in the body of the loop, of course.
True. I'm ingesting HoP at the moment, hopefully some of that will
rub off into better structured code.
More information about the london.pm
mailing list