Granted though, I'm feeling like I'm missing something very obvious. So I may just be dumb, here.
Here's the scenario: I have the following code. It looks fairly straightforward: I create a new, empty list, then try to assign to element 10. That works fine. Then I dump out the array with Data::Dumper.
Then I create a new variable, assign a dummy string to it, and try to dump out my original array, again.
And I get a core dump, along with a bunch of "Attempt to free unreferenced scalar." warnings. How many? 10. Which is how many undefined elements are in my array, before the 11th element, which I defined.
Now to be honest, I *think* I can see what's going on: I create a new array, then fill in the 11th element, but leave the first 10 elements undefined. What seems to be happening is that Perl is getting rid of elements 0-9 (dropping their reference count to 0, then reclaiming the memory. Then Perl tries to write the data for the new variable ($base) over the memory originally held by my (still in scope) array.
So, the question: can anyone reproduce my results, which I've posted below? I'm running Perl5.005_03:
So it's possible that this is a weird bug on my machine, and also possible that it's a bug in my version of Perl, fixed in 5.6. Who knows. Can anyone reproduce it, and if so, is it fixed in 5.6? (I don't have 5.6). Here's the code:Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=linux, osvers=2.2.5-22smp, archname=i386-linux
And the results:#!/usr/bin/perl -w use strict; use Data::Dumper; my @comps; $comps[10] = "foo bar"; print Dumper \@comps; my $base = "Foo bar"; print Dumper \@comps;
Thanks.$VAR1 = [ undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 'foo bar' ]; Bizarre copy of ARRAY in aassign at /usr/lib/perl5/5.00503/Data/Dumper +.pm line 207. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Attempt to free unreferenced scalar. Segmentation fault (core dumped)
In reply to Core Dumping with Arrays by btrott
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |