G'day Mark.Allan,

There are a number of issues with what you posted. One or more of these may be the cause of your problems. You'll need to adjust your problem description and/or data and/or expected output as described here:

If you copy and paste your code and data, we will see exactly what you're seeing. Trying to make multiple guesses as to what is and isn't a typo is both annoying and error-prone. Please bear this in mind with any future posts.

I believe this code should be close to what you want. You may need to make changes where the assumptions and guesses I've documented are incorrect.

#!/usr/bin/env perl use strict; use warnings; my @checks = ( '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', ); my %data; while (<DATA>) { my ($server, $fs) = (split /::/)[0, 1]; $fs = canonicalise_fs($fs); $data{both}{join '::' => $server, $fs} = undef; $data{server}{$server} = undef; $data{fs}{$fs} = undef; } for (@checks) { print "'$_',\t"; my $server = /server=([^:]+)/ ? $1 : ''; my $fs = /FS=([^:]+)/ ? $1 : ''; $fs = canonicalise_fs($fs); if (exists $data{both}{join '::' => $server, $fs}) { print ''; } elsif (exists $data{server}{$server} or exists $data{fs}{$fs}) { print 'PART '; } else { print 'NO '; } print "MATCH\n"; } sub canonicalise_fs { my $fs = shift; $fs .= '/' unless length $fs and $fs =~ /\/$/; return $fs; } __DATA__ 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

Output:

'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', PART MATCH 'server=baraix665, baraix666, baraix667:FS=/data/hp/feeds', NO MATC +H 'server=vmdprd:FS=/opt/tuxedo', PART MATCH 'server=testserver1:FS=/data/repository', NO MATCH

-- Ken


In reply to Re: Matching array elements against file by kcott
in thread Matching array elements against file by Mark.Allan

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.