Front page | perl.beginners |
Postings from May 2012
Strange use of => ?
Thread Next
From:
Owen
Date:
May 11, 2012 19:39
Subject:
Strange use of => ?
Message ID:
20120512123914.0aecc47c@linux-1p6h.site
I found this on the internet to convert an IPv4 address (w.x.y.z) to
a decimal number.
w * 16,777,216 + x * 65,536 + y * 256 + z = decimalNumber
I then found the subroutine, ip2dec in the script below.
The script works, that's not my problem. The problem is "How does it
work"?
The "split /\./" I understand. I've looked at perldoc pack and sort of
see it is taking the ip4 address, packing it up and then unpacking.
But what's with these "=>" things? How is that routine meant to read?
TIA
Owen
========================================================
#!/usr/bin/perl
use strict;
use warnings;
my $Originator = '127.0.0.1';
$Originator = ip2dec($Originator);
my $stored = 'stored';
$stored = "$stored$Originator";
sub ip2dec {
return unpack N => pack CCCC => split /\./ => shift;
}
print "$stored\n";
========================================================
--
Owen
Thread Next
-
Strange use of => ?
by Owen