Mailing List Archive

core dump using map do BLOCK, @input [perl5.001m]
Hello,

# The following program causes a segmentation fault on
# perl5.001m on SVR4/i386 and SunOS 4.x
#
# Changing the code slightly can avoid the core dump, but the results are
# unexpected (it seems like values from the elsif branches are not propagated,
# as @output contains undefs for the 'elsif' cases).
#
# After re-reading the pods, I guess if...elsif...else statements do not have
# a well-defined value, and so the following usage is illegal.
# However, this is a little insidious, and it would be nice if
# "expressions" which do not have well-defined values cause warnings if used
# in a non-null context. And never core dump.
#
# -Jim Avera (avera@hal.com) 11/8/95
sub test
{
@input = @_;
@output = map (
do {
if (/a/) { "got A"; }
elsif (/b/) { "got B"; } # not legal, is seems, but
else { "something else"; } # silently fails or core dumps
},
@input );
print "input = (@_) output = (@output)\n";
}

&test("aaa", "bbb", "ccc", "aaa again", "bbb again", "ccc again" );
Re: core dump using map do BLOCK, @input [perl5.001m] [ In reply to ]
># After re-reading the pods, I guess if...elsif...else statements do not have
># a well-defined value, and so the following usage is illegal.

Hm... I've always done this:

$filename = do {
if ($opt_f) { $opt_f }
elsif ($opt_i) { "<&STDIN" }
else { $DEF_FILE }
};

I never thought it illegal.

--tom