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.@array = $_;
Also, I'm a little puzzled about the use of spaces in these two lines:
It would be easier and more reliable to do those like this:elsif(/^TITLE/) {$title = (s/ /\n\t\t /g,$_); +} elsif(/^ORGANISM/){$org = (s/ /\n\t\t /g,$_);}
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:
That use of grep with split does effectively the same thing as your second code snippet, but in one line instead of several.elsif(/^ACCESSIONS\s+(\S.*)/) { my %seen = (); @accessions = grep { $seen{$_}++ == 0 } split /;\s+/, $1; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |