Note that when you do this:
@array = $_;
you are only assiging a single scalar value to @array -- the array now holds only one element, which is the entire content of $_. You might need to look at using split.

Also, I'm a little puzzled about the use of spaces in these two lines:

elsif(/^TITLE/) {$title = (s/ /\n\t\t /g,$_); +} elsif(/^ORGANISM/){$org = (s/ /\n\t\t /g,$_);}
It would be easier and more reliable to do those like this:
elsif(/^(TITLE)\s+(\S.*)/) { $title = "$1\n\t\t $2\n" } elsif(/^(ORGANISM)\s+(\S.*)/) { $org = "$1\n\t\t $2\n" }

As for handling the "ACCESSIONS" line, if that's where you would want to the second code snippet to fit in, it could go like this:

elsif(/^ACCESSIONS\s+(\S.*)/) { my %seen = (); @accessions = grep { $seen{$_}++ == 0 } split /;\s+/, $1; }
That use of grep with split does effectively the same thing as your second code snippet, but in one line instead of several.

Still, as Gramps points out, you haven't really posed the question very well -- there don't seem to be any duplicate strings in your original data sample, I can only guess about how the second code snippet is supposed to fit in with the first one, and there's no way to tell what you're really trying to do with your array(s). Try posting a reply to him that follows his instructions.

(updated to fix code tags, and to make sure %seen was initialized in my last code snippet)


In reply to Re: how to remove duplicate strings? by graff
in thread how to remove duplicate strings? by heidi

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.