From: Jarkko Hietaniemi Date: Mon, 10 Sep 2001 12:39:25 +0000 (+0000) Subject: Warn against using bare v-strings as IP addresses X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b2463a05821963ff7ae3ec80e805d188f6d7f16;p=p5sagit%2Fp5-mst-13.2.git Warn against using bare v-strings as IP addresses (okay if using the wrappers from Socket) p4raw-id: //depot/perl@11974 --- diff --git a/pod/perldata.pod b/pod/perldata.pod index ffb47f0..968588d 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -333,13 +333,13 @@ anything more complicated in the subscript will be interpreted as an expression. A literal of the form C is parsed as a string composed -of characters with the specified ordinals. This provides an alternative, -more readable way to construct strings, rather than use the somewhat less -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. +of characters with the specified ordinals. This form, known as +v-strings, provides an alternative, more readable way to construct +strings, rather than use the somewhat less 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. print v9786; # prints UTF-8 encoded SMILEY, "\x{263a}" print v102.111.111; # prints "foo" @@ -348,6 +348,8 @@ omitted. 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. +Note that using the v-strings for IPv4 addresses is not portable unless +you also use the inet_aton()/inet_ntoa() routines of the Socket package. The special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that diff --git a/pod/perlport.pod b/pod/perlport.pod index 9abaff6..f8f17a1 100644 --- a/pod/perlport.pod +++ b/pod/perlport.pod @@ -423,6 +423,14 @@ simple, platform-independent mailing. The Unix System V IPC (C) is not available even on all Unix platforms. +Do not use either the bare result of C) or the to represent +IPv4 addresses: both forms just pack the four bytes into network order. +That this would be equal to the C language C struct (which is +what the socket code internally uses) is not guaranteed. To be +portable use the routines of the Socket extension, such as +C, C, and C. + The rule of thumb for portable code is: Do it all in portable Perl, or use a module (that may internally implement it with platform-specific code, but expose a common interface).