Can I use v strings for IPv4 addresses?

The camel book suggests that V-strings can be used to represent IPv4 addresses:

$ipaddr = 204.148.40.9;   # the IPv4 address of oreilly.com

But perldata on the topic "Version Strings":

Note that using v-strings for IPv4 addresses is not portable unless you also use inet_aton () / inet_ntoa () Socket routines.

I have two questions:

1) Why is the use of v-lines not portable?
2) What is the “standard” way to convert ip address from dot notation to integer? It seems that it unpack "N", <v-string>can sometimes cause problems.

+3
source share
1 answer

"" - inet_aton, IP-, , ? , , , , IO:: Socket.

, , , ( C, , , Perl), pack , - , , , . , unpack "N", pack "C4", split /\./, "1.2.3.4" ( 16909060 == 0x01020304).

+5

Source: https://habr.com/ru/post/1776493/


All Articles