in reply to Re: help with strict
in thread help with strict

I think that explanation is misleading. If what you say were true, I would expect this test to pass:

use Test::More tests => 1; my %empty_hash; my $value = 1; $value = $empty_hash{empty_value}; is( $value, 1, 'undef from hash should not overwrite defined value' );

Your second option (testing the definedness of the hash value assignments) is correct, though.

Replies are listed 'Best First'.
Re^3: help with strict
by davidj (Priest) on Jun 04, 2004 at 06:25 UTC
    Maybe I am missing something here. Why should undef from a hash not overwrite a defined value? When I code something like

    $value = $empty_hash{empty_value};

    and $empty_hash{empty_value} has not been defined, $value will certainly get assigned undef since undef is the return value of the attemped hash reference. Or is it that a return value from a hash reference getting assigned is conditional upon the hash value being defined?
    If I am wrong, please let me know because I have always thought otherwise.

    davidj

      You're right, that's exactly what happens. I thought one possible explanation of your previous response might lead people to think otherwise, though I don't really know why anymore. I apologize for the confusion.