Just a couple data points for you... On 5.00503 for linux, it doesn't dump. With 5.6.1 it does. However, with warnings on in 5.6.1 I get this: (note, lines 13 & 14 refer to the foreach stanza)
% 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: As crazy noted... a well placed keys() in your foreach loop seems to solve the problem.....

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.