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

Does $record->src return a string or a list? If it returns a string you'll want:
my %count; for my $record (@records) { if ($count{$record->src}++) { $record->duplicate(1); # or however you set the duplicate flag } }
Note: if a string is duplicated, the first Entry object with that src value will not have its duplicate flag set but all matching Entry objects will.

Replies are listed 'Best First'.
Re^4: objects and duplicates
by lkperl (Initiate) on Apr 27, 2008 at 19:19 UTC

    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

      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?