in reply to Re^2: Understanding Perl context (removing duplicates from array)
in thread Understanding Perl context

Its misleading, because the next maintainer might think he can replace undef with 0 and bang!

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re^3: Understanding Perl context (removing duplicates from array)

Replies are listed 'Best First'.
Re^4: Understanding Perl context (removing duplicates from array)
by AnomalousMonk (Archbishop) on Apr 19, 2015 at 14:27 UTC

    Hmmm... Hadn't thought about that.

    But in the specific case of the OPed code, replacing  undef with 0 (or, indeed, with 1 or any other value) would make no difference: you still end up with a hash of unique keys.

    And in the general case, if code did depend on the difference between  undef and 0 as values, would not this dependence be underscored by the explicit use of  undef as the initializer (reinforced, one would hope, by a comment) rather than the more general  () empty list?


    Give a man a fish:  <%-(-(-(-<

      Sorry, I've had too many coworkers in the past using broken copy and paste code and justifying that the cargo cult worked so far.

      ("Of course it's well tested! I ran it once and nothing bad happened ... " )

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!