X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperldata.pod;h=ac444fa17c4f34876ea843683822e8d06b36d052;hb=c9d5ac959cdfa7a668b3bfbbc2b56923c316ef43;hp=4dbc76564ec5a2cf1f4115ebd197a13de12369de;hpb=191d61a768175782efd32a263e82c70bcb0d1401;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perldata.pod b/pod/perldata.pod index 4dbc765..ac444fa 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -109,14 +109,14 @@ list context to each of its arguments. For example, if you say int( ) -the integer operation provides scalar context for the E +the integer operation provides scalar context for the <> operator, which responds by reading one line from STDIN and passing it back to the integer operation, which will then find the integer value of that line and return that. If, on the other hand, you say sort( ) -then the sort operation provides list context for E, which +then the sort operation provides list context for <>, which will proceed to read every line available up to the end of file, and pass that list of lines back to the sort routine, which will then sort those lines and return them as a list to whatever the context @@ -129,7 +129,8 @@ assignment to an array or hash evaluates the righthand side in list context. Assignment to a list (or slice, which is just a list anyway) also evaluates the righthand side in list context. -When you use Perl's B<-w> command-line option, you may see warnings +When you use the C pragma or Perl's B<-w> command-line +option, you may see warnings about useless uses of constants or functions in "void context". Void context just means the value has been discarded, such as a statement containing only C<"fred";> or C. It still @@ -274,7 +275,6 @@ integer formats: 0xff # hex 0377 # octal 0b011011 # binary - v102.111.111 # string (made of characters "f", "o", "o") String literals are usually delimited by either single or double quotes. They work much like quotes in the standard Unix shells: @@ -282,7 +282,7 @@ double-quoted string literals are subject to backslash and variable substitution; single-quoted strings are not (except for C<\'> and C<\\>). The usual C-style backslash rules apply for making characters such as newline, tab, etc., as well as some more exotic -forms. See L for a list. +forms. See L for a list. Hexadecimal, octal, or binary, representations in string literals (e.g. '0xff') are not automatically converted to their integer @@ -331,7 +331,13 @@ readable interpolation form C<"\x{1}\x{14}\x{12c}\x{fa0}">. This is useful for representing Unicode strings, and for comparing version "numbers" using the string comparison operators, C, C, C etc. If there are two or more dots in the literal, the leading C may be -omitted. Such literals are accepted by both C and C for +omitted. + + print v9786; # prints UTF-8 encoded SMILEY, "\x{263a}" + print v102.111.111; # prints "foo" + print 102.111.111; # same + +Such literals are accepted by both C and C for doing a version check. The C<$^V> special variable also contains the running Perl interpreter's version in this form. See L. @@ -366,7 +372,8 @@ A word that has no other interpretation in the grammar will be treated as if it were a quoted string. These are known as "barewords". As with filehandles and labels, a bareword that consists entirely of lowercase letters risks conflict with future reserved -words, and if you use the B<-w> switch, Perl will warn you about any +words, and if you use the C pragma or the B<-w> switch, +Perl will warn you about any such words. Some people may wish to outlaw barewords entirely. If you say @@ -398,13 +405,13 @@ plain paranoid, you can force the correct interpretation with curly braces as above. A line-oriented form of quoting is based on the shell "here-document" -syntax. Following a CE> you specify a string to terminate +syntax. Following a C<< << >> you specify a string to terminate the quoted material, and all lines following the current line down to the terminating string are the value of the item. The terminating string may be either an identifier (a word), or some quoted text. If quoted, the type of quotes you use determines the treatment of the text, just as in regular quoting. An unquoted identifier works like -double quotes. There must be no space between the CE> and +double quotes. There must be no space between the C<< << >> and the identifier. (If you put a space it will be treated as a null identifier, which is valid, and matches the first empty line.) The terminating string must appear by itself (unquoted and with no @@ -576,8 +583,8 @@ hash. Likewise, hashes included as parts of other lists (including parameters lists and return lists from functions) always flatten out into key/value pairs. That's why it's good to use references sometimes. -It is often more readable to use the C<=E> operator between key/value -pairs. The C<=E> operator is mostly just a more visually distinctive +It is often more readable to use the C<< => >> operator between key/value +pairs. The C<< => >> operator is mostly just a more visually distinctive synonym for a comma, but it also arranges for its left-hand operand to be interpreted as a string--if it's a bareword that would be a legal identifier. This makes it nice for initializing hashes: @@ -743,6 +750,28 @@ C<*HANDLE{IO}> only works if HANDLE has already been used as a handle. In other words, C<*FH> must be used to create new symbol table entries; C<*foo{THING}> cannot. When in doubt, use C<*FH>. +All functions that are capable of creating filehandles (open(), +opendir(), pipe(), socketpair(), sysopen(), socket(), and accept()) +automatically create an anonymous filehandle if the handle passed to +them is an uninitialized scalar variable. This allows the constructs +such as C and C to be used to +create filehandles that will conveniently be closed automatically when +the scope ends, provided there are no other references to them. This +largely eliminates the need for typeglobs when opening filehandles +that must be passed around, as in the following example: + + sub myopen { + open my $fh, "@_" + or die "Can't open '@_': $!"; + return $fh; + } + + { + my $f = myopen("; + # $f implicitly closed here + } + Another way to create anonymous filehandles is with the Symbol module or with the IO::Handle module and its ilk. These modules have the advantage of not hiding different types of the same name