Mailing List Archive

Refined 'strange regexp' bug - lexicals ignored in favour of globals.
Here is a re-distilled bug:

----------------------------------- Snip --------------------------------
#!/usr/local/bin/perl -w

@a = qw(block.S block1.S block2.S block3.S block4.S);

$blk = 'rubbish';

sub does_not_work
{
my($blk, $incref) = @_;
if (@pages = grep(s#(${blk}[0-9]+)\.S#$1#, @{$incref}))
{
print "@pages\n";
}
else
{
print "No pages!\n";
}
}

&does_not_work('block',\@a);

----------------------------------- Snip --------------------------------

The root cause of the problem is that global '$blk' is being used
in the regexp expansion rather than the my $blk.

Strangely removing {} but otherwise avoiding the 'possible array',
makes it work:

if (@pages = grep(s#($blk([0-9]+))\.S#$1#, @{$incref})) # extra ()
if (@pages = grep(s#($blk\d+)\.S#$1#, @{$incref})) # \d

Work as expected.

If you turn on 'use strict' - perl owns up to what it is doing:

Global symbol "blk" requires explicit package name at ...

So does having 'local' $blk rather than 'my'

If you remove the global definition if $blk it *also* works,
but with "Use of uninitialized value ..." warnings.

----------------------------------------------------------------------

This is perl5.001m + Gurusamy Sarathy's patches.

Summary of my perl5 (patchlevel 1) configuration:
Platform:
osname=sunos, osver=4.1.3, archname=sun4-sunos
uname='sunos pluto 4.1.3 1 sun4m '
hint=recommended
Compiler:
cc='gcc', optimize='-O2 -g', ld='ld'
cppflags='-DDEBUGGING'
ccflags ='-DDEBUGGING'
ldflags =''
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, randbits=31
Libraries:
so=so
libpth=/lib /usr/lib /usr/ucblib /usr/local/lib
libs=-lgdbm -ldbm -ldb -ldl -lm -lc -lposix
libc=
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef
cccdlflags='-fpic', ccdlflags=' ', lddlflags='-assert nodefinitions'