Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: If you believe in Lists in Scalar Context, Clap your Hands

by JavaFan (Canon)
on Oct 29, 2008 at 11:37 UTC ( #720207=note: print w/replies, xml ) Need Help??


in reply to Re^4: If you believe in Lists in Scalar Context, Clap your Hands
in thread If you believe in Lists in Scalar Context, Clap your Hands

Is the "operators provide context to their operands" pattern of thought really what all programmers are doing when they program in Perl, or is it something perl does for them so they don't have to worry about it?
Well, perl provides the context (to the operands), but it's something programmers have to consider. But that's not any different then that in $a + $b, perl does the addition, but the programmer has to consider the result, and realize that it's usually different from $a * $b.

Context is an integral part of Perl programs. perl will do the handling behind the screens, telling each operator/function which context it is in - but it's the programmer who has to consider the difference between having the operator/function in the various contexts in can be in.

Replies are listed 'Best First'.
Re^6: If you believe in Lists in Scalar Context, Clap your Hands
by mr_mischief (Monsignor) on Oct 29, 2008 at 14:14 UTC
    In most simpler syntactic constructs, though, I think perl just does what the author of the code expects with the Perl they wrote. In the interests of maintainability, most of the more complex issues of context don't come up in most of the code I write or see from others.

    There are a few immensely important idioms that make use of mixing expressions in list and scalar context in the same statement very useful, but if one thinks of them as "idioms", they're likely not to question the specifics. An idiom is something that doesn't necessarily translate directly to other languages by definition, after all.

    We've been using contrived examples in which we're taking the length of static-length lists. They could have been arrays, but those arrays still could have had their lengths computed in a separate statement.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://720207]
help
Chatterbox?
[atcroft]: .oO(It is a well-known, well-tried module that has probably encountered more corner-cases and oddities than the average mortal programmer can imagine when trying to roll their own...)
[atcroft]: .oO(*Blah* It, I meant....)
[james28909]: omg
[james28909]: im just finding out that july and august have 31 days?
[atcroft]: stevieb: Apparently it was contagious....
[atcroft]: james28909: Make both hands into fists, place them together (with thumbs concealed), and every knuckle is a month (starting with Jan.) has 31 days, every dip (between knuckles) does not....

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2017-04-29 04:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.