#!/sbin/perl -w use strict; use Data::Dumper; my @providerCloudSequence; my %idlcodes; open(my $iniFH, '<', '/tmp/user_defined_connection.ini') or die "Unable to open file:$!\n"; while(<$iniFH>) { chomp; my @providerCloudClass = split('=',$_); push @providerCloudSequence, $providerCloudClass[0]; if ($@) { print "Script Failed to get the Sequence....Exiting the Script\n"; exit 1; } #my %idlcodes = map { split /=|\s+/; } <$iniFH>; my ($k, @r) = split /=|\Q||/; $idlcodes{$k} = [ map [ split /,/ ], @r ]; } if($@){ print "Script Failed to create the hash....Exiting the Script\n"; exit 1; } close $iniFH; print Dumper \%idlcodes; my @interfaceSampleAliases = { "AFGHD_NORTH", "NORTHERN_IIDID_IPV123", "IDL_SOUTH", "IDL_SOUTH_IUID", "SOUTHERN_IND_IPV" }; foreach (@interfaceSampleAliases){ my $correctKey = getCorrectKey($_, %idlcodes, @providerCloudSequence) print $correctKey; } } # Providercloudsequence helps to maintain the precedence of the input file # idlcodes is the hasp map where key is the key from file and value is an arracy of arrays ...see below the output of same sub getCorrectKey($$$){ my $interfaceAlias = $_[0]; foreach ($_[2]) { # This is where I need the help , I want to get the value from # hash %idlcodes using the key from @providerCloudSequence # The value of %idlcodes is kind of multiple Arrays where I want to # grep $interfaceAlias against each with a AND in between elements # and OR in between arrays , if true this is match } } ##Data Dumper Output : Hash looks like 'NORTH_IPV' => [ [ 'IDL', 'NORTHERN' ], [ 'VIDL', 'NORTH' ], [ 'IDL', 'NORTH' ] ], 'MANAGEMENT' => [ [ 'IDL' ], [ 'CIDL' ] ], 'SOUTH_IPV' => [ [ 'IDL', 'SOUTHERN' ], [ 'CIDL', 'SOUTH' ], [ 'IDL', 'SOUTH' ] ]

#### Expected output InterfaceAlias correctKey "AFGHD_NORTH" Doesnt Match anything so return NULL "NORTHERN_IIDID_IPV123" Doesnt Match anything so return NULL "IDL_SOUTH", SOUTH_IPV "IDL_SOUTH_IUID", SOUTH_IPV "SOUTHERN_IND_IPV" Doesnt Match anything so return NULL "IDL_NORTH_IPV" NORTH_IPV "IDL_ABDGJF" MANAGEMENT