Dyrcona

Enterprise Style

Mar 25th, 2022 (edited)
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #Perl example
  2. foreach my $file (@ARGV) {
  3. if (open(my $input, "<", "$file")) {
  4. while (my $bib = <$input>) {
  5. chomp($bib);
  6. if ($queryh->execute($bib)) {
  7. my $rows = $queryh->fetchall_arrayref;
  8. if ($rows && $rows->[0]) {
  9. my $record = MARC::Record->new_from_xml($rows->[0]->[0]);
  10. $record->insert_grouped_field($field);
  11. unless ($updateh->execute(clean_marc($record), $bib)) {
  12. warn "Update of bib $bib failed";
  13. }
  14. }
  15. }
  16. }
  17. close($input);
  18. } else {
  19. warn "Can't open < $file: $!";
  20. }
  21. }
  22.  
  23. #Common Lisp Example
  24. (defun sample-dist (n dist &optional with-removal)
  25. "Get a random sample as a list from a dist."
  26. (let ((scale (loop for v being the hash-values in dist summing v)))
  27. (loop repeat n collect
  28. (let ((r (* scale (random 1.0)))
  29. (acc 0))
  30. (loop for k being the hash-keys in dist using (hash-value v)
  31. do (progn
  32. (incf acc v)
  33. (when (>= acc r)
  34. (when with-removal
  35. (remhash k dist)
  36. (decf scale v))
  37. (return k))))))))
Add Comment
Please, Sign In to add comment