in reply to What protects me from doing this stupid thing..?

perldoc perlop Operator Precedence Associativity

The || operator has a higher precedence than the comma, so your code should work as you intend. What do you mean by, it doesn't work?

As I read it, that should assign the param "some_var" to the value of supplied by the hash or 10 if that is false.

- Miller

  • Comment on Re: What protects me from doing this stupid thing..?

Replies are listed 'Best First'.
Re^2: What protects me from doing this stupid thing..?
by Cody Pendant (Prior) on Aug 12, 2007 at 02:19 UTC
    Sorry, I've just realised that my error was elsewhere, and the code does in fact work. Thanks for the help with undefined versus false though.


    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
      Still, I thought there was (arguably) a valid point made.

      Given that perl -we '10' produces the "Useless use of a constant in void context" warning, couldn't it be argued (by someone that wanted to be extremely picky) that perl -we '0 || 10' should produce the same (or similar) warning ?

      Cheers,
      Rob
        They might be picky, but it's morely likely they misunderstand the meaning of "Useless" in this context. Execution of perl -we "10" returns an error because it does absolutely nothing. In contrast, perl -we "0 || 10" makes a choice. It matters not that the choice is ultimately unnecessary. The constant value is examined in order to make the choice; therefore, it is a useful value. Perl cannot be expected to determine whether or not a programmer makes poor choices. It's like the Oracle: it cannot see past a choice it does not understand.