http://www.perlmonks.org?node_id=1070535

Mark.Allan has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, just wondered if you can guide me on a more accurate way and a better solution of matching array elements against file content in below scenario. I have an array with data as follows:-

ARRAY $VAR1 = [ 'server=bar116aix,bar117aix:FS=/tmp', 'server=cvmfsser1, cvmfsser2:FS=/opt/apps', 'server=cvmfsser3::FS=/opt/apps' 'FS=/bar/cut/data03:NO', 'server=baraix665, baraix666, baraix667:FS=/data/hp/feeds', 'server=vmdprd:FS=/opt/tuxedo', 'server=testserver1:FS=/data/repository' ];

I also have a file, in the following format as follows

FILE <server>::<fs>::<team> vmaprd::/opt/vmaprd/application::intel vmclprd::/opt/vmclprd/apps/oracle::db_support vmdprd::/opt/vmdprd/db2::db_support cvmfsser1::/opt/apps/::app_support cvmfsser3::/opt/apps/::app_support d87ser1::/opt/db2ese::db_support aix5server::/bar/cut/data03::aix_sup linuxvm001::/bar/cut/data04::linux_sup

What I am looking for is an accurate match, if the line is complete match (ie server and fs) exist in the line of the file then this is a MATCH, if only server or file system exists in the line then this is PART MATCH and if server or FS does not exist then NO MATCH

Example

So looking through the array the following would match, part-match or not match against the file

'server=bar116aix,bar117aix:FS=/tmp', NO MATCH 'server=cvmfsser1, cvmfsser2:FS=/opt/apps', PART MATCH 'server=cvmfsser3::FS=/opt/apps' MATCH 'FS=/bar/cut/data03:NO', MATCH 'server=baraix665:FS=/data/hp/feeds', NO MATCH 'server=vmdprd:FS=/opt/tuxedo', PART MATCH 'server=testserver1:FS=/data/repository' NO MATCH

Here's where I am at present but its not working as I want, because the bind operator matches for example just the /opt of a file system even if the fs /opt//db2ese does not exist in the array

#OPEN FILE open(FH,"<$fs") || die ("cannot open file"); while (<FH>) { ($host,$cfg,$sup) = split /::/,$_; $cfg =~ s/\*//g; push @FS,$cfg}; #LOOP THROUGH ARRAY and look for MATCH foreach my $item (@config){ print "$item\n"; foreach my $item2 (@FS){ if ($item =~ /$item2/){ print "MATCH = $item ------> $item2\n";} } }