in reply to Troubles with Complex Data Structures
Here's how I might write the foreach loop:
The trick here is that, once you have a reference to a sublevel of the data structure -- in this case $ip_port, which points to one of the inner arrays -- you can work directly from that reference.foreach my $ip_port (@{$data{$ip}}) { # $ip_port = ["192.168.0.3"," +43035"]; $sock = IO::Socket::INET->new(Proto => 'udp', PeerAddr => $ip_port->[0], PeerPort => $ip_port->[1] ); $sock->send($in) or die "send: $!"; print "Sent to $ip_port->[0]:$ip_port->[1]\n"; }
|
|---|