AnyEvent::Loop and $_

Marc Lehmann schmorp at schmorp.de
Thu Feb 9 18:08:32 CET 2012


On Thu, Feb 09, 2012 at 05:23:30PM -1200, Mons Anderson <mons at rambler-co.ru> wrote:
> I've found a bad condition, when io watcher in pure-perl loop became broken

Yes, thats common in perl.

> I propose either localize $_ or use my variable

Yes, local is the usual defensive progamming idiom when modifying global
variables. AnyEvent already does that, but you have to do that in your
code as well, for any global variable you modify. "for" already does that
for example.

As a rule of thumb in perl coding: if you modify a global variable,
restore it before returning.

You can use AnyEvent::Strict (AE_STRICT=1 ./myprog) to catch these kinds
of bugs - it should pinpoint which watcher is causing the problem when it
happens.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list