Hi Monks.

So now I have 1 array, and 1 arraylist.

@tocheck : Apple Corn Pie Fish %checkfrom: Meat => Fish Apple Pork Bacon Fruit => Apple Pie Orange Beef

Well that's the gist of it at least. I'm trying to remove the values that are in the array @tocheck from the hash %checkfrom. So the end result is something like this:

Meat=> Pork Bacon Fruit => Orange Beef

Well but there are several thousand keys in the %checkfrom, and probably about the same number of elements in @tocheck. Is there anything faster than checking like this? Also how can I remove the value from the value key pair? I know delete $checkfrom{$_} deletes the entire key/value pair.

foreach $checking(@tocheck){ for (keys %checkfrom){ if ($checkfrom{$_} eq $checking){ #does }

Thanks Monks!

Update:

Well, since this example isnt working, I shall post my full code and files up here.

Activpospf.txt PF01486 PF00319 PF04947 PFACTest.txt PF01486 : C12345 C23456 PF00319 : C15234 PF12345 : C00001 C12345 PF98765 : C00000

These are just small files so I can test them out. The actual files are much bigger.

#!/usr/bin/perl use Modern::Perl; use File::Slurp qw/read_file write_file/; my $pfaminput ='Activpospf.txt'; my $seedinput ='PFACtest.txt'; #open POSITIVEOUT, ">", 'ActivPosdata.txt'; #open NEGATIVEOUT, ">", 'ActivNeg.txt'; my %seedin =map{chomp; /(.+)\s+\:\s+(.+)/;$1=>$2;} read_file $seedinp +ut; my $pfam; my @tocheck; my @negative; for $pfam(read_file $pfaminput){ chomp ($pfam); if (defined $seedin{$pfam}) { my @splitter =split(/ /, $seedin{$pfam}); push (@tocheck, @splitter); delete $seedin{$pfam};}}

What I intend to get is to remove the entire lines from PFACtest which have the PF values that are in Activpospf.txt, and also to use the numbers that are within those lines that are removed, and remove them from the rest of the file. i.e. this:

PF12345 : C00001 PF98765 : C00000

Thanks!


In reply to Removal of values in array from array list by jemswira

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.