http://www.perlmonks.org?node_id=160724


in reply to Re: undef'ing @arrays caveat
in thread undef'ing @arrays caveat

i don't find that so strange weird. in each case, the assignment to hash assumed a second argument of undef. it's as if you assigned %hash=undef,undef;. perl just helps you do what you mean. as in the post above, list context is assumed due to the type of the lvalue of the assignment operation.

however, %hash=undef=>undef; may not do what you mean, if you don't know what you mean. here, the difference between , and => is plain.

# $VAR1 = { # 'undef' => undef # };

p.s. assignment is pretty much guaranteed to do just that--assign something. if you want to assign an empty hash, you'll have to assign one %hash = ()

~Particle ;Þ

Replies are listed 'Best First'.
Re: Re: Re: undef'ing @arrays caveat
by lestrrat (Deacon) on Apr 20, 2002 at 03:25 UTC

    Oh I see, the '' is the stringified undef. Yes, that I appreciate, but

    however, %hash=undef=>undef; may not do what you mean, if you don't know what you mean. here, the difference between , and => is plain.

    Boy, did I sound *that* clueless? I was just verifying the various somevariable = undef behavior before I post an answer, and just came upon one that seemed weird strange. ugh.

      i'm sorry, that bit wasn't meant for you. that was meant for all readers. i should have been more clear, perhaps by posting that bit to the original poster. sorry for any unintended offense :-)

      ~Particle ;Þ