Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: "but" versus "and"

by jonadab (Parson)
on Sep 27, 2004 at 20:11 UTC ( [id://394330]=note: print w/replies, xml ) Need Help??


in reply to Re: "but" versus "and"
in thread A "but" operator.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://394330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found