bloonix has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I'm wondering about the following code snippet that triggers a segmentation fault if the script exit.
Output:
Output: 29837 29838 29839 29840 Segmentation fault (core dumped)
My question is now why that happend? Do you have an answer?
Regards,
Jonny
I'm wondering about the following code snippet that triggers a segmentation fault if the script exit.
my $i = 30000; my %h = (new => {}); my $r = \%h; for (0..$i) { print $_, " "; $r = $r->{new}; $r->{new} = {}; } print "end\n";
Output:
I test it with different iterations and from 24.000 the segfault is produced definitely. If I try to undef %h the segfault is produced immediate....29998 29999 30000 end Segmentation fault (core dumped)
my $i = 30000; my %h = (new => {}); my $r = \%h; for (0..$i) { print $_, " "; $r = $r->{new}; $r->{new} = {}; } undef %h; print "end\n";
Output: 29837 29838 29839 29840 Segmentation fault (core dumped)
My question is now why that happend? Do you have an answer?
Regards,
Jonny
Edit: g0n - changed pre tags to code tags
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Segmentation fault
by Joost (Canon) on Jun 25, 2007 at 20:11 UTC | |
by jettero (Monsignor) on Jun 25, 2007 at 20:18 UTC | |
by Joost (Canon) on Jun 25, 2007 at 20:21 UTC | |
by dave_the_m (Monsignor) on Jun 25, 2007 at 20:40 UTC | |
by jasonk (Parson) on Jun 26, 2007 at 12:56 UTC | |
by jettero (Monsignor) on Jun 26, 2007 at 14:09 UTC | |
by bloonix (Monk) on Jun 25, 2007 at 20:30 UTC | |
by Joost (Canon) on Jun 25, 2007 at 20:47 UTC | |
by martin (Friar) on Jun 25, 2007 at 22:11 UTC | |
by Joost (Canon) on Jun 25, 2007 at 22:29 UTC |
Back to
Seekers of Perl Wisdom