On Wednesday 22 August 2001 13:40, Mark Maunder wrote:
> This is probably an oldie, but assigning an undef to a hash creates a hash
> with a single element (which I'm guessing is undef). Isn't this counter
> intuitive. I would have expected the hash to be empty if the undef that is
> assigned is in scalar context.

This:

        #!/usr/bin/perl
        use warnings;
        use strict;
        use Data::Dumper;

        my %test = ( hi => 'hello' );
        print Dumper( \%test );

        undef %test;
        print Dumper( \%test );

Yields:

        $VAR1 = {
                  'hi' => 'hello'
                };
        $VAR1 = {};

Which is expected in my book.

If you mean assigning like this:

        %test = undef;

You'll get an error, as expected.

If you mean assigning like this:

        $test{'hi'} = undef

Then you'll get an undefined element, as expected.

Did this answer the question?  Perhaps you could post a little sample code 
that illustrates the question.

Regards,

Troy




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to