Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: I need help with the error "Modification of non-creatable array value attempted"

by Anonymous Monk
on Jul 14, 2014 at 20:14 UTC ( #1093609=note: print w/replies, xml ) Need Help??


in reply to I need help with the error "Modification of non-creatable array value attempted"

IPv4 addresses are 32-bit; they are often handled as integer values (uint32_t).

Perl provides pack and unpack for working with rigid-format data. For example:

my $ip = "123.223.11.22"; my @ip = split /\./, $ip; my $p = pack "C4", @ip; # packed as 4-octet thing my $x = unpack "N", $p; # ip as unsigned int # work on integer values, e.g. masking is just ($x & $y) $p = pack "N", $x; # re-pack the value my $bitvec = unpack "B32", $p; my $quad = join q(.), unpack "C4", $p; print "as bitvector: $bitvec\n"; print "as dotted quad: $quad\n";

  • Comment on Re: I need help with the error "Modification of non-creatable array value attempted"
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1093609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2022-12-03 09:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?