Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
how can a variable have a (or more) value(s) and still be undefined?

You wouldn't normally want the variable to be undef, if it has meaningful values. But what if its value is an error code? Say, you want to return undef (so that the calling code knows it is getting an error, not a real value), but you want to return different _kinds_ of undef -- for example, if the error message is due to a builtin failing maybe you want to return ($! but undef), so that the calling code can try (if it wants to bother) to figure out what went wrong. One of the Apocalypse articles talks about unthrown protoexceptions -- that is, returning a value that is undef (to signal failure) but also knows how to complain in a meaningful way if it is thrown as an exception.

However, the string/number duality is easier to see the benefit of for normal code. For example, my $postoffice = ("Galion" but 44833); Of course, you won't _have_ to do things this way. You can always go with more standard data structures, such as my $postoffice = +{ name => "Galion", zip => 44833 }; however, that requires the calling code to understand your data structure. In some cases, especially for modules, it might be better to return an object that knows how to behave different ways depending on how the calling code chooses to treat it. In other words, an object that understands and can respond to context. 0 but true is probably the most obviously useful example. We have people doing "0 but true" in Perl5 already, when returning false is wrong but 0 is the correct number. This is a symptom of the fact that the rich set of different kinds of context in Perl really makes it necessary for objects to be able to evaluate differently in different contexts.

"In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68

In reply to Re^2: "but" versus "and" by jonadab
in thread A "but" operator. by muba

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (3)
    As of 2018-05-25 11:26 GMT
    Find Nodes?
      Voting Booth?