#!/usr/bin/perl use strict ; use warnings ; use diagnostics ; use threads ; use Config ; $Config{useithreads} || die("\n---> Please recompile Perl with \ included. \n") ; # IP parameterization of network elements. my %device_ip = ( "core" => "3.3.3.3", "border" => "5.5.5.5", ) ; # Initialize devices' pool of threads. my $index = 0 ; my @device_thread = () ; while( my ($key, $value) = each %device_ip ) { push( @device_thread, threads->new(\&thread_job($key, $device_ip{$key}, $index))->join ) ; $index = $index+1 ; } # Worker thread subroutine. sub thread_job { my ($device, $ip, $index) = @_ ; my $ithread = threads->tid() ; print "[id=$ithread @ $index] : IP address \"$ip\" corresponds to device \"$device\". \n" ; }