dgaramond2 has asked for the wisdom of the Perl Monks concerning the following question:

Sigh, I've been bitten by this at least 3-4 times. First a couple of years ago with some version of YAML. And then with some version of YAML::Parser::Syck. And just now with YAML::Syck. I'm using Perl, Ruby, PHP, and to a much less extent Python. Strangely, all of them but Perl have had no problem with No being false, but interestingly in Perl we are confused every now and then and load No as the string 'No'. What's going on here? :-)

Replies are listed 'Best First'.
Re: YAML's No in Perl
by audreyt (Hermit) on Mar 13, 2006 at 19:12 UTC
    use YAML::Syck; $YAML::Syck::ImplicitTyping = 1; Load("No"); # undef
    I had ImplicitTyping on, but Ingy told me it should be off by default to save time and reduce confusion and improve compatibility. So... Blame him. :-)

      Hi audrey.

      Save time? Execution time? Please explain... I think YAML::Syck is fast enough for all of my needs.

      Improve compatibility with what, older Perl modules (all of which are 'alpha' or 'beta' and should not guarantee API/backwards compatibility anyway)? I would vote for better interoperability with the other YAML-using languages, as it is one of YAML's biggest strength.

      Reduce confusion? Hm, that's not what I experienced. Implicit typing is also one of YAML's basic features.

      So, turn it and keep it on please :)

        Okay, I did add a prominient notice to YAML::Syck 0.38 and credited you for it in the ChangeLog. Thanks!
      I think Ingy's right, implicit typing should be off by default. It caused all kinds of bugs including turning an md5 hash string that happened to match /^\d+e\d+$/ into NaN.

      Implicit typing should only be enabled if it doesn't interfere with round-tripping, Perl's polymorphic scalars seem to me to make this impossible.

      ImplicitTyping--

Re: YAML's No in Perl
by adrianh (Chancellor) on Mar 13, 2006 at 12:06 UTC
    Strangely, all of them but Perl have had no problem with No being false, but interestingly in Perl we are confused every now and then and load No as the string 'No'. What's going on here? :-)

    Bugs from the sound of it. I'm sure the developers would love a nicely wrapped up test case and an RT bug report :-)

Re: YAML's No in Perl
by wazoox (Prior) on Mar 13, 2006 at 12:11 UTC
    Perl evaluates 0, undef and '' (empty string) as false in scalar context. It evaluates () (empty list) as false in list context. Any other string evaluates as true. I don't see what's wrong with that; if "No" evaluates false, what about "NO", "no", "N" ? What about "Non", "Niet", "Nein" and "La'" ?
      I don't see what's wrong with that; if "No" evaluates false, what about "NO", "no", "N" ? What about "Non", "Niet", "Nein" and "La'" ?

      In YAML it can be a representation of a boolean value - see Boolean Language-Independent Type for YAML™ Version 1.1 for details. So it can make sense for a YAML parser to translate this to a false value in Perl land.

        I see. It could be then a nice feature to add to the YAML module. After all, it's only an alpha release : latest is 0.58.