in reply to Re^3: objects and duplicates
in thread objects and duplicates

Hello,

$record->src does return a string. Your code works perfectly fine, thank you.

I didn't express myself clearly: I said flag for $record->duplicate, but in fact it should hold the number of times the sentence is duplicate, so it's more a count than a flag.

I still think it's possible to achieve this, but how?

Thank you

Replies are listed 'Best First'.
Re^5: objects and duplicates
by pc88mxer (Vicar) on Apr 27, 2008 at 19:50 UTC
    I didn't express myself clearly: I said flag for $record->duplicate, but in fact it should hold the number of times the sentence is duplicate, so it's more a count than a flag.
    In that case your object approach isn't modeling the problem correctly - storing the number of duplicates in the Entry object doesn't make sense. Your original approach is better, but I'd do it this way:
    my %count; for (@items) { $count{$_}++ } my @dups = grep { $count{$_} > 1 } @items;
    or
    my (%count, @dups); for (@items) { $count{$_}++ == 1 && push(@dups, $_) }
    In each case $count{$sentence} contains the number of occurrences of $sentence. Will this work for you?