jemswira has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Removal of values in array from array list
by ikegami (Patriarch) on Aug 30, 2012 at 19:12 UTC | |
by jemswira (Novice) on Aug 31, 2012 at 08:15 UTC | |
by ikegami (Patriarch) on Sep 17, 2012 at 05:21 UTC | |
Re: Removal of values in array from array list
by Limbic~Region (Chancellor) on Aug 30, 2012 at 19:17 UTC | |
by Anonymous Monk on Aug 31, 2012 at 00:26 UTC | |
by jemswira (Novice) on Aug 31, 2012 at 12:37 UTC | |
Re: Removal of values in array from array list
by CountZero (Bishop) on Aug 30, 2012 at 19:26 UTC | |
Re: Removal of values in array from array list
by philiprbrenan (Monk) on Aug 30, 2012 at 20:15 UTC |