I have the below requirements * Read the sample data file /tmp/user_defined_connection.ini

MANAGEMENT=IDL||CIDL NORTH=IDL,NORTHERN||VIDL,NORTH||IDL,NORTH SOUTH=IDL,SOUTHERN||CIDL,SOUTH||IDL,SOUTH

Each Key here can have the multiple such values ',' signifies an AND operations and '||' is an OR operation * I need to check this against another string $instance and for each value , so I take the first key MANAGEMENT and get its values and check against isntance .... `$instance` contains `IDL` or `CIDL` In next iteration same instance will be checked against the second key which is `NORTH` and if true the function should return NORTH so basically I need to check the instance against each value one by one and then return the key which i find the last... below is the code written till now

How the check should work in this example checks if InterfaceAlias contains (IDL OR CIDL) , then checks if same interfaceAlias contains [(IDL AND NORTH) OR (VIDL AND NORTH) OR (IDL AND NORTHERN) , then checks if same interfaceAlias contains (IDL AND SOUTH) OR (CIDL AND SOUTH) OR (IDL AND SOUTHERN) So we have to check against all values in hash %idlcodes and return the last key with which match was TRUE The sequence is managed by the array `@providerCloudSequence` Adjacency of words is not important For example SOUTH_XXX_CIDL or even "SOUTH IDL IPV WITH SPACES" should match SOUTH_IPV....These are just examples it is basically a contains match....though the structure of file is fixed...(the data may vary)

#!/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 Sc +ript\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 Scr +ipt\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, @provide +rCloudSequence) print $correctKey; } } # Providercloudsequence helps to maintain the precedence of the in +put file # idlcodes is the hasp map where key is the key from file and valu +e 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 wa +nt to # grep $interfaceAlias against each with a AND in between elem +ents # 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' ] ] <p><b> #### 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 </b></p>


In reply to checking the string against all values of multidimension hashmap in perl by learnP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.