Skip to content

Commit

Permalink
addbib: correctly re-open database (#734)
Browse files Browse the repository at this point in the history
* I discovered the cause of the close() error I was seeing when editing a database entry with vi, then hitting y to continue
* When continuing a new entry is expected to be appended to the database
* The file was closed and re-opened between executing vi; however, due to the "my" declaration in the open() call an alias of the global filehandle $DATABASE was made
* Make sure there is only one $DATABASE variable; now I can correctly append new entries after editing an entry with vi
  • Loading branch information
mknos authored Sep 9, 2024
1 parent 84b1e0d commit 66c1cae
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bin/addbib
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ if (defined $opt_p) {
}

my $database = shift;
open my $DATABASE, '>>', $database or die "can't append to $database: $!";
my $DATABASE;
open $DATABASE, '>>', $database or die "can't append to $database: $!";

my $inst = <<_EOINST;
Addbib will prompt you for various bibliographic fields.
Expand Down Expand Up @@ -108,7 +109,7 @@ while (1) {
close $DATABASE or die "can't close $database: $!";
system($1, $database) == 0
or die "system '$1 $database' failed: $?";
open my $DATABASE, '>>', $database or die "can't open $database: $!";
open $DATABASE, '>>', $database or die "can't open $database: $!";
print "Continue? (y) ";
$_ = <>;
}
Expand Down

0 comments on commit 66c1cae

Please sign in to comment.