Ah, I did it using the following code:
my @array_q3=(); #create the array to store all words in the file
open INFILE3, "<file";
while( my $line3 = <INFILE3>)
{
chomp $line3;
push @array_q3, $line3;
}
close INFILE3;
#sort the array so we can identify the duplicates
my @sorted_array_q3 = sort(@array_q3);
my @unique_array;
#iterate through the sorted array and check for unique elements
foreach my $element ( @sorted_array_q3 )
{
if ( ! grep( /$element/, @unique_array ) )
{
push( @unique_array, $element );
}
}
#print the unique elements in the file clean.acc\n";
open OUTFILE3, ">unique_codes";
for (my $m=0; $m<=$#unique_array; $m++)
{
print OUTFILE3 $unique_array[$m]."\n";
}
close OUTFILE3;
My problem here is with grep, since I seem to miss one element... The element has the code J00148 and apparently there is a conflict with another element, namely AJ001487.
What must I add in my grep conditional?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|