X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfunc.pod;h=833e89182579e65ecc26db20897d3843f6617e29;hb=9b5c3821be1f2a9a84772171c8bbadbf9cfc4a53;hp=96bb041ad7427f38bc460f410576b54d8bd3ac3b;hpb=40454f2627208fbd759d13437538e524c882cfac;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 96bb041..833e891 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -614,7 +614,7 @@ false otherwise. See the example under C. Changes the permissions of a list of files. The first element of the list must be the numerical mode, which should probably be an octal -number, and which definitely should I a string of octal digits: +number, and which definitely should I be a string of octal digits: C<0644> is okay, C<'0644'> is not. Returns the number of files successfully changed. See also L, if all you have is a string. @@ -2097,7 +2097,34 @@ IPs that the connection might have come in on. =item getsockopt SOCKET,LEVEL,OPTNAME -Returns the socket option requested, or undef if there is an error. +Queries the option named OPTNAME associated with SOCKET at a given LEVEL. +Options may exist at multiple protocol levels depending on the socket +type, but at least the uppermost socket level SOL_SOCKET (defined in the +C module) will exist. To query options at another level the +protocol number of the appropriate protocol controlling the option +should be supplied. For example, to indicate that an option is to be +interpreted by the TCP protocol, LEVEL should be set to the protocol +number of TCP, which you can get using getprotobyname. + +The call returns a packed string representing the requested socket option, +or C if there is an error (the error reason will be in $!). What +exactly is in the packed string depends in the LEVEL and OPTNAME, consult +your system documentation for details. A very common case however is that +the option is an integer, in which case the result will be an packed +integer which you can decode using unpack with the C (or C) format. + +An example testing if Nagle's algorithm is turned on on a socket: + + use Socket; + + defined(my $tcp = getprotobyname("tcp")) + or die "Could not determine the protocol number for tcp"; + # my $tcp = Socket::IPPROTO_TCP; # Alternative + my $packed = getsockopt($socket, $tcp, Socket::TCP_NODELAY) + or die "Could not query TCP_NODELAY SOCKEt option: $!"; + my $nodelay = unpack("I", $packed); + print "Nagle's algorithm is turned ", $nodelay ? "off\n" : "on\n"; + =item glob EXPR @@ -2492,36 +2519,44 @@ for details, including issues with tied arrays and hashes. =item localtime EXPR +=item localtime + Converts a time as returned by the time function to a 9-element list with the time analyzed for the local time zone. Typically used as follows: # 0 1 2 3 4 5 6 7 8 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = - localtime(time); + localtime(time); All list elements are numeric, and come straight out of the C `struct -tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the -specified time. $mday is the day of the month, and $mon is the month -itself, in the range C<0..11> with 0 indicating January and 11 -indicating December. $year is the number of years since 1900. That -is, $year is C<123> in year 2023. $wday is the day of the week, with -0 indicating Sunday and 3 indicating Wednesday. $yday is the day of -the year, in the range C<0..364> (or C<0..365> in leap years.) $isdst -is true if the specified time occurs during daylight savings time, -false otherwise. +tm'. C<$sec>, C<$min>, and C<$hour> are the seconds, minutes, and hours +of the specified time. -Note that the $year element is I simply the last two digits of -the year. If you assume it is, then you create non-Y2K-compliant -programs--and you wouldn't want to do that, would you? +C<$mday> is the day of the month, and C<$mon> is the month itself, in +the range C<0..11> with 0 indicating January and 11 indicating December. +This makes it easy to get a month name from a list: -The proper way to get a complete 4-digit year is simply: + my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); + print "$abbr[$mon] $mday"; + # $mon=9, $mday=18 gives "Oct 18" - $year += 1900; +C<$year> is the number of years since 1900, not just the last two digits +of the year. That is, C<$year> is C<123> in year 2023. The proper way +to get a complete 4-digit year is simply: -And to get the last two digits of the year (e.g., '01' in 2001) do: + $year += 1900; - $year = sprintf("%02d", $year % 100); +To get the last two digits of the year (e.g., '01' in 2001) do: + + $year = sprintf("%02d", $year % 100); + +C<$wday> is the day of the week, with 0 indicating Sunday and 3 indicating +Wednesday. C<$yday> is the day of the year, in the range C<0..364> +(or C<0..365> in leap years.) + +C<$isdst> is true if the specified time occurs during Daylight Saving +Time, false otherwise. If EXPR is omitted, C uses the current time (C). @@ -2908,7 +2943,9 @@ works for symmetry, but you really should consider writing something to the temporary file first. You will need to seek() to do the reading. -File handles can be opened to "in memory" files held in Perl scalars via: +Since v5.8.0, perl has built using PerlIO by default. Unless you've +changed this (ie Configure -Uuseperlio), you can open file handles to +"in memory" files held in Perl scalars via: open($fh, '>', \$variable) || .. @@ -2971,6 +3008,8 @@ Examples: } } +See L for detailed info on PerlIO. + You may also, in the Bourne shell tradition, specify an EXPR beginning with C<< '>&' >>, in which case the rest of the string is interpreted as the name of a filehandle (or file descriptor, if numeric) to be @@ -3556,7 +3595,7 @@ and C<'87654321'> are big-endian. If you want portable packed integers you can either use the formats C, C, C, and C, or you can use the C> and C> -modifiers. These modifiers are only available as of perl 5.8.5. +modifiers. These modifiers are only available as of perl 5.9.2. See also L. =item * @@ -3797,9 +3836,14 @@ array in subroutines, just like C. =item pos Returns the offset of where the last C search left off for the variable -in question (C<$_> is used when the variable is not specified). May be -modified to change that offset. Such modification will also influence -the C<\G> zero-width assertion in regular expressions. See L and +in question (C<$_> is used when the variable is not specified). Note that +0 is a valid match offset, while C indicates that the search position +is reset (usually due to match failure, but can also be because no match has +yet been performed on the scalar). C directly accesses the location used +by the regexp engine to store the offset, so assigning to C will change +that offset, and so will also influence the C<\G> zero-width assertion in +regular expressions. Because a failed C match doesn't reset the offset, +the return from C won't change either in this case. See L and L. =item print FILEHANDLE LIST @@ -4519,11 +4563,8 @@ You can effect a sleep of 250 milliseconds this way: select(undef, undef, undef, 0.25); Note that whether C. B: One should not attempt to mix buffered I/O (like C or ) with C