heidi has asked for the wisdom of the Perl Monks concerning the following question:
and this is the sample data file:open (PIR,'/home/sampir.txt'); while (<PIR>) { if (/^ENTRY/) {$entry = $_;} elsif(/^TITLE/) {$title = (s/ /\n\t\t /g,$_); +} elsif(/^ORGANISM/){$org = (s/ /\n\t\t /g,$_);} elsif(/^ACCESSIONS/){$acc = $_;} else { @arr = $_; } if (defined $array2[0]) { @array = split('',$arr[0]); } } print @array;
I refered perldoc and i tried using,ENTRY CCHU #type complete TITLE cytochrome c [validated] - human ORGANISM #formal_name Homo sapiens #common_name man ACCESSIONS A31764; A05676; I55192; A00001 MGDVEKGKKIFIMKCSQCHTVEMGDVEKGGKHKTGPNLHGLFGRKTGQAPGYSYTAANKNKGIIWGEDTL +MEYLENPKKYIP ENTRY CCCZ #type complete TITLE cytochrome c - chimpanzee (tentative sequence) ORGANISM #formal_name Pan troglodytes #common_name chimpanzee ACCESSIONS A00002 GDVEKGKKIFIMKCSQCHTVEKGSSSKHKSSSTGPNLHGLFGRKTGQAPGYSYTAANKNKGIIWGED ENTRY CCMQR #type complete TITLE cytochrome c - rhesus macaque (tentative sequence) ORGANISM #formal_name Macaca mulatta #common_name rhesus macaq +ue ACCESSIONS A00003 GDVEKGKKIFIMKCSQCHTVEKGGSSSSKHKTGPNLHGLFGAAAAAAAARKTGQAPGYSYTAANKSSSSN +KGITWGEDTLMEYLENPKKYIPGTKMIFVGIKKKEE ENTRY CCMKP #type complete TITLE cytochrome c - spider monkey ORGANISM #formal_name Ateles sp. #common_name spider monkey ACCESSIONS A00004 GDVFKGKRIFIMKCSQCHTVESSSSKGGKHKTGPNLHGLFGSSSSSSSSSSR
But what it does is, it removes the alphabets which repeats within the string.i dont want that to happen,i want all the 4 strings(the one which is next to accession line) in an array without duplicate strings. Plz help me out. thanks.my @unique = (); my %seen = (); foreach my $elem ( @array ) { next if $seen{ $elem }++; push @unique, $elem; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to remove duplicate strings?
by GrandFather (Saint) on Oct 30, 2006 at 04:35 UTC | |
by heidi (Sexton) on Oct 30, 2006 at 05:42 UTC | |
|
Re: how to remove duplicate strings?
by graff (Chancellor) on Oct 30, 2006 at 05:24 UTC | |
by heidi (Sexton) on Oct 30, 2006 at 06:02 UTC | |
by graff (Chancellor) on Oct 30, 2006 at 06:39 UTC | |
by heidi (Sexton) on Oct 30, 2006 at 09:08 UTC | |
|
Re: how to remove duplicate strings?
by bobf (Monsignor) on Oct 30, 2006 at 06:04 UTC | |
|
Re: how to remove duplicate strings?
by holcapek (Sexton) on Oct 30, 2006 at 11:48 UTC |