I have put together a script to compare user input with a db and want to extract the bits of the input which do not match the db contents

This is very convoluted and I feel is crying out for a hash but I'm not sure how to create the hash or what to do with it once I've got it!!

Having put this together I feel sure that if a kindly monk would show me a more efficient way then it would be really useful to me in terms of improving my skills

Thanks

#comma delimited user input @words = split(/,/, $words); #copy of array for later @words2 = @words; open FH, "$data" or die "Can't open $data: $!"; flock (FH, 1) or die "Can't lock $data for reading: $!"; my @all = <FH>; close FH; #iterate through user input comparing with db while (@words) { my $item = shift (@words); $count++; foreach my $line (@all) { ($one,$two,undef,$four,$spare_1,$spare_2) = split "\t",$line; chomp; if ($item eq "$four") { push (@matched, $item); push (@counted, $count); last; } } } #iterate through @counted applying undef to matched items in copy of u +ser input array while (@counted) { my $item = shift (@counted); $words2[$item -1] = undef; } #remove undef items from user input leaving only unmatched items. foreach my $item (@words2) { unless ($item eq "") { push (@uniq, $item); } } #@matched contains only matched items #@uniq contains only unmatched items

In reply to extracting non matched items from an array - the hard way! by jonnyfolk

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.