Bug#627613: Mistaken aliasing of $& somewhere in the bowels of Perl

Ian Jackson ijackson at chiark.greenend.org.uk
Sun May 22 17:13:08 UTC 2011


Package: perl
Version: 5.10.1-17

Observe the transcript below.  You'll see that the other match against
$thing seems to somehow pollute the use of $& in the assignment to
Num, but only in the simple case.

If this is a real bug it probably wants to go upstream, but I thought
it might be sensible to ask you as the Debian maintainer to sanity check.

This bug seems to appear on lenny too (5.10.0-19lenny3).

Thanks,
Ian.


$ cat perl-bug.pl 
use strict;
use warnings;

use Data::Dumper;

my $thing= '1-word';

print STDERR Dumper(
    { Num => ($thing =~ m/^\d+/ ? $& : die)
    });
# Works, Num => "1"

print STDERR Dumper(
    { Num => ($thing =~ m/^\d+/ ? $& : die),
      Word => !!($thing =~ m/word/)
    });
# Broken, Num => "word"

print STDERR Dumper(
    { Num => ($thing =~ m/^\d+/ ? "$&" : die),
      Word => !!($thing =~ m/word/)
    });
# Works, Num => "1"

print STDERR Dumper(
    { Num => ($thing =~ m/^\d+/ ? int $& : die),
      Word => !!($thing =~ m/word/)
    });
# Works, Num => 1
$ perl -w perl-bug.pl 
$VAR1 = {
          'Num' => '1'
        };
$VAR1 = {
          'Num' => 'word',
          'Word' => 1
        };
$VAR1 = {
          'Num' => '1',
          'Word' => 1
        };
$VAR1 = {
          'Num' => 1,
          'Word' => 1
        };
$






More information about the Perl-maintainers mailing list