Parse an IP Address: Difference between revisions

→‎{{header|Perl 6}}: Fix issue with arrays-in-arrays causing spaces in output on modern Perl 6.
(→‎{{header|Perl 6}}: Fix issue with arrays-in-arrays causing spaces in output on modern Perl 6.)
Line 1,466:
{ @*by16 = @$<h16> }
 
| [ (<h16>) +% ':']? '::' (<h16>) +% ':' <?{ @$0 + @$1 <= 8 }>
{ @*by16 = |@$0, |('0' xx 8 - (@$0 + @$1)), |@$1 }
 
| '::ffff:' <IPv4>
{ @*by16 = |('0' xx 5), 'ffff', |(by8to16 @*by8) }
}
 
token d8 { (\d+) <?{ $0 < 256 }> }
token d16 { (\d+) <?{ $0 < 65536 }> }
token h16 { (<:hexdigit>+) <?{ @$0 <= 4 }> }
 
token port {
Line 1,521:
say $addr;
if @*by16 {
say " IPv6: ", @*by16».map({:16(~$_)})».fmt("%04x").join;
say " Port: ", $*port if $*port;
}
Anonymous user