Re: remove duplicates from an array!
by shmem (Chancellor) on Jan 07, 2008 at 22:56 UTC
|
Not only is this incomprehensible, but the ink is ugly and the paper is from the wrong kind of tree.
-- Professor, EECS, George Washington University
Your array declaration is incorrect and unorderly. Whitespace scattered wildly, tabs not written as such... say rather
@ICE = (
"30F-WKS\t`1781183799.xxxx1'\tIC---;",
"30F-WKS\t`1781183799.xxx11'\tIC---;",
"ADM34A3F9\t`1781183799.41455'\tIC---;",
);
The result you see in %seen indicates that your array @ICE contains 1218 elements, of which none is an array.
The elements, if I get correctly what you mean by
30F-WKS (tab) `1781183799.xxx11' (tab) IC---;
are strings with tab separated fields. If you want to make each string into an array and check for uniqueness of their first element, you have to split them and make anonymous arrays of the first element from each split return, along with the original string as the second element, grep the list of anonymous arrays for definedness in %seen (that part of your code is correct) and finally extract the second element (which is the original string) from each anonymous array grep returns:
my @ICEU = map { $_->[1] } grep { !$seen{$_->[0]}++ } map { [ (split /
+\t/, $_)[0], $_ ] } @ICE;
Always use -w!
Your second declaration of @ICEU with my masks the first one.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] [select] |
Re: remove duplicates from an array!
by FunkyMonk (Chancellor) on Jan 07, 2008 at 22:38 UTC
|
When I transform your code into something I can run (it really does help us and you):
my @ICE = map { [ split /\s*\(tab\)\s*/ ] } <DATA>;
my %seen;
my @ICEU = grep { !$seen{$_->[0]}++ } @ICE;
print Dumper \@ICE;
print Dumper \%seen;
__DATA__
30F-WKS(tab)`1781183799.xxxx1' (tab) IC---;
30F-WKS (tab) `1781183799.xxx11' (tab) IC---;
ADM34A3F9 (tab) `1781183799.41455' (tab) IC---;
I get
$VAR1 = [
[
'30F-WKS',
'`1781183799.xxxx1\'',
'IC---;
'
],
[
'30F-WKS',
'`1781183799.xxx11\'',
'IC---;
'
],
[
'ADM34A3F9',
'`1781183799.41455\'',
'IC---;
'
]
];
$VAR1 = {
'ADM34A3F9' => 1,
'30F-WKS' => 2
};
Which looks pretty much as it should, doesn't it?
It looks like Hercynium is right. @ICE doesn't contain what you think it does
| [reply] [d/l] [select] |
Re: remove duplicates from an array!
by assemble (Friar) on Jan 07, 2008 at 22:42 UTC
|
| [reply] |
Re: remove duplicates from an array!
by kirillm (Friar) on Jan 07, 2008 at 22:47 UTC
|
| [reply] |
|
Hi Kirill,
Thanks for the response. In My previous post the data was in a file. Now for this problem the data is in an array.
| [reply] |
|
| [reply] |
Re: remove duplicates from an array!
by apl (Monsignor) on Jan 08, 2008 at 02:16 UTC
|
Your advise will be appreciated
Drop the class. | [reply] |
Re: remove duplicates from an array!
by Hercynium (Hermit) on Jan 07, 2008 at 22:23 UTC
|
Could you please post a dump of what you have in @ICEU? The rest of your code looks correct, but perhaps the data you're searching through isn't what you expect?
print Dumper \@ICEU;
| [reply] [d/l] [select] |
|
Hi it only displays the first line:-
30F-WKS(tab)`1781183799.xxxx1' (tab) IC---;
can you suggest anternate coding | [reply] [d/l] |
|
Looks like the people in the posts below have the answer for you... your data isn't what you think it is, but it can be transformed pretty easily. :) Cheers!
| [reply] |
Re: remove duplicates from an array!
by Anonymous Monk on Jan 08, 2008 at 21:02 UTC
|
Don't YELL!
All-uppercase is harder to read than mixed-case, and may be interpreted as being written by somebody who doesn't believe in proof-reading.
Advice? This is a very common problem; search through the monastery (check out the link on this page called "Super Search"). Many of the monks (including me) can be grouchy, and we react badly to questions which do not seem to have been well-thought out. And watch out for the English-usage nazis.
| [reply] |
|
Seconded: Please do not yell in the monastery. Some of us are meditating.
| [reply] |
Re: remove duplicates from an array!
by Anonymous Monk on Jan 09, 2008 at 14:39 UTC
|
I would love it if you stopped getting your way with every homework question that you shamelessly ask here.
I've been studying perl for three months, have no experience in programming whatsoever, and even I find your questions trivial. I suggest you try to answer them for yourself first; bothering experts with your school exercises seems nothing less than a waste of human resources. | [reply] |
Re: remove duplicates from an array!
by Anonymous Monk on Jan 09, 2008 at 00:00 UTC
|
Good god that is horrid!! Can't anyone in Bangalore write decent Perl???
I am sorry I think you are stuck at the help desk forever | [reply] |