OK, My comments below apply to this and Uri's similar comments. I should have said: this infinite loop is easy to detect because: 1. the pattern is constant 2. the data (here $_) is not modified in the loop
Both points are obvious to a person. In this simple and important special case it is also easy for most compilers (of languages other than Perl). In principle quite complex code can be analyzed to determine accurately that the data is not modified. I conclude that the Perl compiler has either * chosen to not do this kind of analysis, or * any such analysis is not connected to the error mechanism. I am curious if Dan S. has any comments on this w.r.t. Parrot. Steve > -----Original Message----- > From: Ronald J Kimball [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 27, 2004 5:33 PM > To: Tolkin, Steve > Cc: [EMAIL PROTECTED] > Subject: Re: [Boston.pm] why no warning about this infinite loop > > > On Tue, Jan 27, 2004 at 05:04:03PM -0500, Tolkin, Steve wrote: > > # run using e.g. echo hello | perl this-file > > > > # Why doesn't perl produce a warning from the following. It is an > > # infinite loop. If I add a /g modifier to the m// it works fine. > > > > while (<>) { > > while (m/([a-z])/) { # warning infinite loop!!! > > print $1, "\n" > > } > > } > > > > > > /// > > > > In general it is hard to detect infinite loops, but in this > case it is easy, > > because the pattern is a constant. I think this is a very common > > special case, and is worth detecting. > > The pattern in the below code is also constant, but there is > no infinite > loop: > > while (<>) { > while (m/([a-z])/) { > print $1, "\n"; > $_ = substr($_, 1); > } > } > > As you say, it is hard to detect infinite loops. :) > > > Ronald > _______________________________________________ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm

