develooper Front page | perl.perl5.porters | Postings from June 2008

[perl #51514] s/// on tied hashes

From:
Bram via RT
Date:
June 29, 2008 14:20
Subject:
[perl #51514] s/// on tied hashes
Message ID:
rt-3.6.HEAD-18542-1214736502-671.51514-15-0@perl.org
On Fri Mar 07 07:14:49 2008, mawic@gmx.de wrote:
> There seems to be a bug regarding tied hashes. If s/// is applied to 
a 
> string in such a hash, it either has no effect or Perl crashes. The 
outcome 
> is somewhat random, little changes in the code can completely change 
the 
> result. Minimal test case:
> 
> -8<------------------------------------
> my $hr = { a => 'abc' };
> tie my %h, 'CaseInsHash', $hr;
> $h{A} =~ s/(.)/x$1x/g;
> print $h{A};
> 
> package CaseInsHash;
> sub TIEHASH() { bless $_[1] }
> sub FETCH()   { $_[0]->{lc($_[1])} }
> sub STORE()   { $_[0]->{lc($_[1])} = $_[2] }
> -8<------------------------------------
 

That code doesn't segfault with me but

#!/usr/bin/perl -l

my $hr = { a => 'abc' };
tie my %h, 'CaseInsHash', $hr;
$h{A} =~ s/(.)/x$1x/g;
print $h{A};

package CaseInsHash;
sub TIEHASH() { bless $_[1] }
sub FETCH() { print "FETCH ($_[1])" if 0; $_[0]->{lc($_[1])} }
sub STORE() { print "STORE ($_[1] = $_[2])" if 0; $_[0]->{lc($_[1])} = 
$_[2] }

__END__

does. (Which is essentially the same thing).


I couldn't get 5.8.8 to segfault, but 5.10.0 did segfault.

Trying the same code with maint (5.10.x - eventually 5.10.1) did not 
segfault neither did perl-current (blead).

Both output:
xaxxbxxcx


Is it possible for you to build perl-current and test as well?


Kind regards,

Bram



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About