Update: As crazy noted... a well placed keys() in your foreach loop seems to solve the problem.....% perl5.6.1 -w test.pl Use of uninitialized value in substr at test.pl line 14. Attempt to free unreferenced scalar at test.pl line 13. Use of uninitialized value in substr at test.pl line 14. Attempt to free unreferenced scalar at test.pl line 13. # other invocations.... % perl5.00503 -w test.pl [nothing] % perl5.00503 test.pl [nothing] % perl5.6.1 test.pl Segmentation fault (core dumped)
Update 2: It looks like deleting the key before you get to the corresponding value in the foreach loop is causing problems...
#!/usr/bin/perl use strict; ### show what we're looping over (a,1,b,2,c,3) my %hash = (a=>1, b=>2, c=>3); for (%hash) { print "OK: $_\n"; } ### check the value *before* we attempt to delete the key ### i.e. 1 before a, 2 before b, 3 before c %hash = (a=>1, b=>2, c=>3); for (reverse %hash) { substr $_, 0, 1; delete($hash{$_}) if /[a-z]/; print "Still-OK: $_\n"; } ### emulate your structure where we can potentially delete ### a key first, then loop over the value associated with it %hash = (a=>1, b=>2, c=>3); for (%hash) { substr $_, 0, 1; # <== segfaults here when testing value associated +with deleted key delete($hash{$_}) if /[a-z]/; print "Not-OK: $_\n"; } __END__ =head1 OUTPUT OK: a OK: 1 OK: b OK: 2 OK: c OK: 3 Still-OK: 3 Still-OK: c Still-OK: 2 Still-OK: b Still-OK: 1 Still-OK: a Not-OK: a Not-OK: Segmentation fault (core dumped)
-Blake
In reply to Re: Why does this dump core?
by blakem
in thread Why does this dump core?
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |