"Exiting eval via next" [perl v5.14]

Peter Haworth pmh at edison.ioppublishing.com
Mon Nov 7 11:55:48 GMT 2011

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.

Peter Haworth                | I unicycled 140 miles coast to coast for BHF
pmh at edison.ioppublishing.com | Please sponsor me at justgiving.com/pmh1wheel
"Beekeeping is like being a lion tamer,
 but with smaller lions, and more of them."
		-- arp

This email (and attachments) are confidential and intended for the addressee(s) only. If you are not the intended recipient please notify the sender, 
delete any copies and do not take action in reliance on it. Any views expressed are the author's and do not represent those of IOP, except where specifically 
stated. IOP takes reasonable precautions to protect against viruses but accepts no responsibility for loss or damage arising from virus infection. 
For the protection of IOP's systems and staff emails are scanned automatically.” 

Institute of Physics Registered in England under Registration No 293851 
Registered Office:  76/78 Portland Place, London W1B 1NT  

More information about the london.pm mailing list