![]() Each operator and function decides which sort of value would be most appropriate to return in scalar context. It might do two totally different things. Remember the following important rule: There is no rule that relates the behavior of an expression in list context to its behavior in scalar context, or vice versa. For example, time+86_400 always means time() + 86_400.įor functions that can be used in either a scalar or list context, nonabortive failure is generally indicated in scalar context by returning the undefined value, and in list context by returning the empty list. ![]() These include such functions as time and endpwent. Useless use of integer addition in void context at - line 1.Ī few functions take no arguments at all, and therefore work as neither unary nor list operators. For example, the third line above produces: print (.) interpreted as function at - line 1. If you run Perl with the use warnings pragma, it can warn you about this. Whitespace between the function and left parenthesis doesn't count, so sometimes you need to be careful: print 1+2+4 # Prints 7. Otherwise it's a list operator or unary operator, and precedence does matter. (The syntax descriptions omit the parentheses.) If you use parentheses, the simple but occasionally surprising rule is this: It looks like a function, therefore it is a function, and precedence doesn't matter. Commas should separate literal elements of the LIST.Īny function in the list below may be used either with or without parentheses around its arguments. Such a list may consist of any combination of scalar arguments or list values the list values will be included in the list as if each individual element were interpolated at that point in the list, forming a longer single-dimensional list value. ![]() In the syntax descriptions that follow, list operators that expect a list (and provide list context for elements of the list) are shown with LIST as an argument. For instance, splice has three scalar arguments followed by a list, whereas gethostbyname has four scalar arguments. If it does both, scalar arguments come first and list argument follow, and there can only ever be one such list argument. A unary operator generally provides scalar context to its argument, while a list operator may provide either scalar or list contexts for its arguments. Thus, a comma terminates the argument of a unary operator, but merely separates the arguments of a list operator. (See the precedence table in perlop.) List operators take more than one argument, while unary operators can never take more than one argument. These differ in their precedence relationship with a following comma. They fall into two major categories: list operators and named unary operators. The functions in this section can serve as terms in an expression. Perlfunc - Perl builtin functions #DESCRIPTION Non-function Keywords by Cross-reference.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |