automake-patches
[Top][All Lists]
Advanced

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

Re: local perl $_ variable is not portable


From: Stefano Lattarini
Subject: Re: local perl $_ variable is not portable
Date: Mon, 17 Jan 2011 01:39:29 +0100
User-agent: KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; )

On Sunday 16 January 2011, Ralf Wildenhues wrote:
> 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'};
>
Oops, this was a *bad* mistake of mine.  Ironically, I'm fully aware
that "my $_" is royally unportable (I used perl 5.8.10 until a few
months ago, and "my $_" don't work with it!), so I guess the above
slipped in only through a botched edit (which, BTW, is not an excuse
for such a mess-up).  I can only apologize about such a stupid,
stupid mistake.

> +      $_ = $h->{'option'};
>
What about using a "good ol' local" here?  E.g.:
  local $_ = $h->{'option'};
That should be portable to any perl 5.x, and a bit safer.

BTW, I'd also add to the ChangeLog entry the "git describe" output
for the commit where I messed things up (if I'm not mistaken, it
should be `v1.11-622-gf90a06c').  For example:

  options: 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.

  Bug introduced in commit `v1.11-622-gf90a06c'.

>        my $where = $h->{'where'};
>        $options->{$_} = $where;
>        if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
> 
> 
Thanks for the patch, and sorry for the botch-up.

Stefano



reply via email to

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