develooper Front page | perl.makemaker | Postings from May 2003

Playing nice with $_ in ExtUtils::Manifest

Thread Next
From:
Ken Williams
Date:
May 19, 2003 14:11
Subject:
Playing nice with $_ in ExtUtils::Manifest
Message ID:
77FC1C9E-8A3E-11D7-A682-003065F6D85A@mathforum.org
Hey,

Unfortunately perl doesn't automatically localize $_ when using 'while 
(<fh>) {...}'.  Witness this one-liner:

   % perl -MO=Deparse -e 'while(<>) {print}'
   while (defined($_ = <ARGV>)) {
       print $_;
   }

So it'll clobber $_ with undef at the end of the block, and if $_ is 
read-only then it'll fail with an error.

I recently ran across this when I got some death-errors in calling some 
of the ExtUtils::Manifest functions from Module::Build.  Those 
functions fail if $_ contains an alias to a read-only variable:

   % perl -MExtUtils::Manifest=maniread -e 'foo(5); sub foo{for(@_) 
{maniread}}'
   Modification of a read-only value attempted at 
/Library/Perl/ExtUtils/Manifest.pm line 185.

The solution is to put "local $_;" before a few while(<fh>) loops in 
ExtUtils::Manifest.

I'd submit a real patch, but:

  % cvs up
  cvs [update aborted]: connect to makemaker.org:2401 failed: Connection 
refused

  -Ken


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