in reply to help with strict

This is why you are getting the uninitialized error.

On line 8, you are simply declaring your variables. As the Camel book explains, when you use "my" to declare variables, they default to undef. In lines 17-28, if the hash values are empty, they will return undef.
You can correct this by explicitly assign a value to each variable on line 8 or by testing the variable assignment values on lines 17-28 before trying to print them on line 33.

hope this helps,
davidj

Replies are listed 'Best First'.
Re^2: help with strict
by chromatic (Archbishop) on Jun 04, 2004 at 00:55 UTC

    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.

      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.