X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperldata.pod;h=50b685816e8146f13c7b3b8cc67614a5eed1b7e9;hb=322edccd6da7b0afb2e0db52c07695cbca6754c9;hp=96941bd885e156cb0c6e2006fa3aa58a39a2b27d;hpb=9f1b1f2d9ab55954ee07a14c4ab04bd3dd1f99d5;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perldata.pod b/pod/perldata.pod index 96941bd..50b6858 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -259,7 +259,7 @@ of sixteen buckets has been touched, and presumably contains all 10,000 of your items. This isn't supposed to happen. You can preallocate space for a hash by assigning to the keys() function. -This rounds up the allocated bucked to the next power of two: +This rounds up the allocated buckets to the next power of two: keys(%users) = 1000; # allocate 1024 buckets @@ -275,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: @@ -283,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 @@ -304,7 +303,8 @@ price is $Z<>100." print "The price is $Price.\n"; # interpreted As in some shells, you can enclose the variable name in braces to -disambiguate it from following alphanumerics. You must also do +disambiguate it from following alphanumerics (and underscores). +You must also do this when interpolating a variable into a string to separate the variable name from a following double-colon or an apostrophe, since these would be otherwise treated as a package separator: @@ -332,7 +332,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. @@ -456,6 +462,22 @@ from each line manually: down from the door where it began. FINIS +If you use a here-doc within a delimited construct, such as in C, +the quoted material must come on the lines following the final delimiter. +So instead of + + s/this/< is a +concatenation of two lists, C<1,> and C<3>, the first of which ends +with that optional comma. C<1,,3> is C<(1,),(3)> is C<1,3> (And +similarly for C<1,,,3> is C<(1,),(,),3> is C<1,3> and so on.) Not that +we'd advise you to use this obfuscation. + A list value may also be subscripted like a normal array. You must put the list in parentheses to avoid ambiguity. For example: @@ -745,6 +776,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