Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Perl example
- foreach my $file (@ARGV) {
- if (open(my $input, "<", "$file")) {
- while (my $bib = <$input>) {
- chomp($bib);
- if ($queryh->execute($bib)) {
- my $rows = $queryh->fetchall_arrayref;
- if ($rows && $rows->[0]) {
- my $record = MARC::Record->new_from_xml($rows->[0]->[0]);
- $record->insert_grouped_field($field);
- unless ($updateh->execute(clean_marc($record), $bib)) {
- warn "Update of bib $bib failed";
- }
- }
- }
- }
- close($input);
- } else {
- warn "Can't open < $file: $!";
- }
- }
- #Common Lisp Example
- (defun sample-dist (n dist &optional with-removal)
- "Get a random sample as a list from a dist."
- (let ((scale (loop for v being the hash-values in dist summing v)))
- (loop repeat n collect
- (let ((r (* scale (random 1.0)))
- (acc 0))
- (loop for k being the hash-keys in dist using (hash-value v)
- do (progn
- (incf acc v)
- (when (>= acc r)
- (when with-removal
- (remhash k dist)
- (decf scale v))
- (return k))))))))
Add Comment
Please, Sign In to add comment