in reply to Odd number of elements in hash assignment warning. Use of uninitialized value warning

Yes. You've committed the same flaw as:
@array = undef;
which is that it makes @array have one element of undef, not zero elements (empty).

Do not use undef for anything other than the scalar undefined value. Your program could use:

my %href = ();
But I'd probably flag that on code review as "potential signs of cluelessness - look very carefully at the remaining code", since that's also the default, and people who override the default with the default tend to make other mistakes. {grin}

-- Randal L. Schwartz, Perl hacker

  • Comment on Re: Odd number of elements in hash assignment warning. Use of uninitialized value warning
  • Select or Download Code

Replies are listed 'Best First'.
RE: Re: Odd number of elements in hash assignment warning. Use of uninitialized value warning
by swiftone (Curate) on Sep 21, 2000 at 20:20 UTC
    "potential signs of cluelessness - look very carefully at the remaining code", since that's also the default

    I think what he means (in less sarcastic terms :) ) is that there is no reason not to simply have:

    my %hash;
    I'm sure some people would defend variable initialization, even to the default, but in general I think it's more readable to simply accept the default (undef) that Perl assigns. Trust Perl. Perl is your friend.
      Initializing variables with undef or () upon creation is a best practice for those who might ever have their code run under mod_perl.
undef has a noun form and verb form. I should have used the verb form
by princepawn (Parson) on Sep 21, 2000 at 20:22 UTC
    You are right. And by the way, Net::FTP was causing problems for us along these lines... it is best to get an array ref from Net::FTP instead of an array because you will get an array with one element (undef) if there are no files resulting from an $ftp->ls call.

    But anyway, undef %h or undef @x will work fine. But the noun form is the one that I errantly used.

    What a dummy am I.

    oops, there I go again. That should've been What a dummy I am... misplaced noun and verb again. heh.