MUST ... RESIST ... URGE ... FOR ... ONEUPMANSHIP!!!

AAAAAAAAAAAHHHHHHHHHGGGGGGGG!!!!!!!  ;)

...

while (my $record = $batch->next) {
  # find 'em
  my @m856 = $record->field('856');

  # get rid of 'em
  $record->delete_field( $_ ) for @m856;

  # map to a hash for direct uniqueness
  %u856 = (map { ($_->as_usmarc => $_) } @m856);

  # then add 'em back
  $record->insert_fields_ordered( values( %u56) );
}



# sorry for the top-posting... and it's untested :)
__END__

--miker


On 7/30/07, Bryan Baldus <[EMAIL PROTECTED]> wrote:
> Note: my comments are untested and may not work without modification. Some
> parts left to the reader to complete.
>
> On Monday, July 30, 2007 2:16 PM, Michael Bowden wrote:
> >   @m856 = sort {$a cmp $b} @m856;
>
> @m856 has MARC::Field objects. Comparing them as such are unlikely to
> produce desired results.
> better might be @m856 = sort {$a->as_usmarc() cmp $b->as_usmarc()} @m856,
> but then you lose the field object. Better might be to leave out that step
> and go on to:
>
> >   my %seen = ();
> >   my @new856 = ();
>
> Instead of going through all fields in the record, you could go through the
> 856s you have gathered, add them to the %seen hash as usmarc (to facilitate
> comparisons), and, as subsequent ones are already seen, delete the field.
> After that, you could sort the fields, delete them, and then add back the
> sorted fields.
>
>       if (@m856) {
>          foreach $f (@m856) {
>    #add this field to seen fields if not seen
>    unless ($seen{$f->as_usmarc}){
>       $seen{$f->as_usmarc} = $f;
>    }#unless seen this field's exact data
>    else {
>       #seen it, so delete current
>              $record->delete_field($f);
>    } #else seen this field
>  } #foreach 856
>
> my @new856 = (); #add values of %seen, sorted according to keys of %seen
> ###sort remaining/deduplicated 856 fields, delete existing fields, and then
> add sorted fields back.
> ###where @new856 contains the values of %seen, sorted according to the keys
> of %seen
>
>    $record->insert_fields_ordered( @new856 );
>
> #########################################
>
> I hope this helps,
>
> Bryan Baldus
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> http://home.inwave.com/eija
>
>
>

Reply via email to