automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

local perl $_ variable is not portable


From: Ralf Wildenhues
Subject: local perl $_ variable is not portable
Date: Sun, 16 Jan 2011 23:02:46 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

On the AIX 5.1 I test on, perl 5.0.8 fails over a recent Options.pm
change:

$ ./tests/automake-1.11a --help
Can't use global $_ in "my" at 
/tmp/build-powerpc-ibm-aix5.2.0.0/../automake/lib/Automake/Options.pm line 263, 
near "my $_ "
Compilation failed in require at /tmp/build-powerpc-ibm-aix5.2.0.0/automake 
line 154.
BEGIN failed--compilation aborted at /tmp/build-powerpc-ibm-aix5.2.0.0/automake 
line 154.

Now, perldoc perlvar documents:
  As $_ is a global variable, this may lead in some cases to unwanted
  side-effects.  As of perl 5.9.1, you can now use a lexical version of $_ by
  declaring it in a file or in a block with "my".  Moreover, declaring "our $_"
  restores the global $_ in the current scope.

I'm currently using the patch below (not tested yet), but you might
prefer something safer?  Otherwise, OK?

Thanks,
Ralf

    Avoid local $_ perl variable, for Perl before 5.9.1.
    
    * lib/Automake/Options.pm (_process_option_list): Do not
    lexically localize $_.  Fixes bootstrap on AIX 5.1.

diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm
index 31052c0..a1dfcde 100644
--- a/lib/Automake/Options.pm
+++ b/lib/Automake/Options.pm
@@ -260,7 +260,7 @@ sub _process_option_list (\%@)
 
   foreach my $h (@list)
     {
-      my $_ = $h->{'option'};
+      $_ = $h->{'option'};
       my $where = $h->{'where'};
       $options->{$_} = $where;
       if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')



reply via email to

[Prev in Thread] Current Thread [Next in Thread]