Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > duplicates

Reply
Thread Tools

duplicates

 
 
julia_2683@hotmail.com
Guest
Posts: n/a
 
      05-29-2007
I would like to find and delete duplicates to reduce the number of
entries I have for each word. Need your help to achieve that.
Input
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated
output
dog -> doggy dogs
want -> wants wanting wanted.

Thanks

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      05-29-2007
On May 29, 1:33 pm, (E-Mail Removed) wrote:
> I would like to find and delete duplicates to reduce the number of
> entries I have for each word. Need your help to achieve that.
> Input
> dog -> doggy
> dog -> dogs
> want -> wants
> want -> wanting
> want -> wanted
> eat -> eaten
> eat -> eating
> eat -> eated
> output
> dog -> doggy dogs
> want -> wants wanting wanted.


What have you tried so far? How did it not meet your expectations?
>From where does this data come, and in what structure do you have it

stored? Have you searched the FAQ?

$ perldoc -q duplicate
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq4.pod
How can I remove duplicate elements from a list or array?


Paul Lalli

 
Reply With Quote
 
 
 
 
Billy N. Patton
Guest
Posts: n/a
 
      05-29-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I would like to find and delete duplicates to reduce the number of
> entries I have for each word. Need your help to achieve that.
> Input
> dog -> doggy
> dog -> dogs
> want -> wants
> want -> wanting
> want -> wanted
> eat -> eaten
> eat -> eating
> eat -> eated
> output
> dog -> doggy dogs
> want -> wants wanting wanted.
>
> Thanks
>

put into a hash
if exists
$hash{dog} .= " dogs";
 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      05-29-2007
On May 29, 10:33 am, (E-Mail Removed) wrote:
> I would like to find and delete duplicates to reduce the number of
> entries I have for each word. Need your help to achieve that.


How about this:

#!/usr/bin/perl

use strict;
use warnings;

my %word;
while (<DATA>) {
chomp;
my ($word1, $word2) = split (/ -> /, $_);
push @{$word{$word1}}, $word2;
}
print($_," -> ",join(" ",@{$word{$_}}),"\n") for keys %word;

__DATA__
dog -> doggy
dog -> dogs
want -> wants
want -> wanting
want -> wanted
eat -> eaten
eat -> eating
eat -> eated

OUTPUT
eat -> eaten eating eated
want -> wants wanting wanted
dog -> doggy dogs


>> eat -> eated


eated???


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      05-29-2007
On Tue, 29 May 2007 11:38:42 -0700, Jim Gibson
<(E-Mail Removed)> wrote:

>Here's a fish:


What's of the elitist clpmisc attitude?


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
Brad Baxter
Guest
Posts: n/a
 
      05-29-2007
On May 29, 4:08 pm, Michele Dondi <(E-Mail Removed)> wrote:
> On Tue, 29 May 2007 11:38:42 -0700, Jim Gibson
>
> <(E-Mail Removed)> wrote:
> >Here's a fish:

>
> What's of the elitist clpmisc attitude?


s/of/with/;
-- elitist (alleged) English speaker

--
Brad

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      05-30-2007
(E-Mail Removed) <(E-Mail Removed)> wrote:
> On May 29, 10:33 am, (E-Mail Removed) wrote:


>>> eat -> eated

>
> eated???



I think that's when something is warmed up in England...


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      05-30-2007
Brad Baxter <(E-Mail Removed)> wrote:
> On May 29, 4:08 pm, Michele Dondi <(E-Mail Removed)> wrote:
>> On Tue, 29 May 2007 11:38:42 -0700, Jim Gibson
>>
>> <(E-Mail Removed)> wrote:
>> >Here's a fish:

>>
>> What's of the elitist clpmisc attitude?

>
> s/of/with/;



Due to the smiley, I think

s/of/become of/;

was the intent.


> -- elitist (alleged) English speaker



I only speak 'merican though, so I may be way off base...


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
jeevs
Guest
Posts: n/a
 
      05-30-2007
On May 29, 11:28 pm, (E-Mail Removed) wrote:
> On May 29, 10:33 am, (E-Mail Removed) wrote:
>
> > I would like to find and delete duplicates to reduce the number of
> > entries I have for each word. Need your help to achieve that.

>
> How about this:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my %word;
> while (<DATA>) {
> chomp;
> my ($word1, $word2) = split (/ -> /, $_);
> push @{$word{$word1}}, $word2;
> }
> print($_," -> ",join(" ",@{$word{$_}}),"\n") for keys %word;
>
> __DATA__
> dog -> doggy
> dog -> dogs
> want -> wants
> want -> wanting
> want -> wanted
> eat -> eaten
> eat -> eating
> eat -> eated
>
> OUTPUT
> eat -> eaten eating eated
> want -> wants wanting wanted
> dog -> doggy dogs
>
> >> eat -> eated

>
> eated???
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)



Hi David .. Sorry but i dint follow the syntax you used

like you used

push (@{$hash{$key}}, $value);

How does this work.. I mean i can understand when one uses @{$arr_ref}
to derefenciate an array ref.
but what does @{$hash{$key}} stands for... IF you can point me to some
data or link that will be fine too...

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      05-30-2007
On May 30, 2:55 am, jeevs <(E-Mail Removed)> wrote:
> On May 29, 11:28 pm, (E-Mail Removed) wrote:
> > my %word;
> > while (<DATA>) {
> > chomp;
> > my ($word1, $word2) = split (/ -> /, $_);
> > push @{$word{$word1}}, $word2;
> > }
> > print($_," -> ",join(" ",@{$word{$_}}),"\n") for keys %word;


> Hi David .. Sorry but i dint follow the syntax you used
>
> like you used
>
> push (@{$hash{$key}}, $value);
>
> How does this work.. I mean i can understand when one uses @{$arr_ref}
> to derefenciate an array ref.
> but what does @{$hash{$key}} stands for...


It's exactly the same thing - @{REF} dereferences the array reference
REF. In @{$arr_ref}, $arr_ref is the array reference. In
@{$hash{$key}}, $hash{$key} is the array reference. That is, the
value of %hash whose key is $key is a reference to an array. Hashes
and arrays can store *any* kind of scalar variable - integers, floats,
strings, and references too.

> IF you can point me to some
> data or link that will be fine too...


perldoc perllol
perldoc perldsc

Paul Lalli

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Removing duplicates from a DropdownList brian richards ASP .Net 1 08-04-2003 04:36 PM
Re: Removing duplicates from a DropdownList S. Justin Gengo ASP .Net 0 08-04-2003 04:31 PM
Re: Removing duplicates from a DropdownList brian richards ASP .Net 0 08-04-2003 04:30 PM
Re: Removing duplicates from a DropdownList William F. Robertson, Jr. ASP .Net 1 08-04-2003 04:16 PM
Removing duplicates from a DropdownList makthar ASP .Net 0 08-04-2003 04:13 PM



Advertisments