develooper Front page | perl.ldap | Postings from March 2011

Net::LDAP::Constant unexpectedly overwriting $_

Thread Next
From:
Marc Lehmann
Date:
March 29, 2011 02:10
Subject:
Net::LDAP::Constant unexpectedly overwriting $_
Message ID:
20110328230140.GA2831@schmorp.de
Hi!

I found that requiring Net::LDAP::Constant trashes the global $_ variable
with "=cut". This can have quite unintended consequences when $_ is already
used by outer code (for example, when loading modules in a loop).

As a general rule, in perl, when you use a global variable, you should save
and restore it (map, for etc. all do this).

But Net::LDAP::Constant doesn't:

   while(<DATA>) {
     last if /^=cut/;

May I suggest a "local $_" before that loop so it doesn't trash global
variables anymore?

Thanks a lot!

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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About