NAME
BibTeX::Parser - A pure perl BibTeX parser
SYNOPSIS
Parses BibTeX files.
use BibTeX::Parser;
use IO::File;
my $fh = IO::File->new("filename");
# Create parser object ...
my $parser = BibTeX::Parser->new($fh, $opts);
# ... and either iterate over entries
while (my $entry = $parser->next ) {
if ($entry->parse_ok) {
my $type = $entry->type;
my $title = $entry->field("title");
my @authors = $entry->author;
# or:
my @editors = $entry->editor;
foreach my $author (@authors) {
print $author->first . " "
. $author->von . " "
. $author->last . ", "
. $author->jr;
}
} else {
warn "Error parsing file: " . $entry->error;
}
}
# ... or read all entries at once
$parser->read();
my $num_entries = $parser->n();
my $entrykeys = $parser->entrykeys();
foreach my $key (@{$entrykeys}) {
my $entry = $parser->entry($key);
...
}
if ($parser->has{'thekey') {
$theentry = $parser->entry('thekey');
}
DESCRIPTION
There are two interfaces for BiBTeX::Parser: the serial one and
the caching one. The serial interface can be used for very large
files. It reads entries one by one, and outputs them using $parser->next()
function. In other cases you might be better off with the caching
interface. It reads all the entries at once, and can output the
list of keys or the entry with the given key.
FUNCTIONS
new
Creates new parser object.
Parameters:
* fh: A filehandle
* opts: a refernce to the hash of options. Among other
options is 'errorlevel', used in the caching interface when
processing a non-parseable entry. Can be 'warn' (the
default), 'erorr', or 'ignore'. Note that in serial
interface the error processing is the responsibility of the
user.
next
Returns the next parsed entry or undef. Cannot be combined with the read interface described below.
read
Read all the entries from the filehandle in the internal cache.
n
Returns the number of entries after read function has been called
entrykeys
Returns the array of keys after read function has been called
entry
Returns an entry with the given key after read function has been called
Parameters:
* key: the key
has
Returns true if the cached file has the given entry
Parameters:
* key: the key
NOTES
The fields author and editor are canonicalized, see BibTeX::Parser::Author.
SEE ALSO
VERSION
version 1.95
AUTHOR
Gerhard Gossen <gerhard.gossen@googlemail.com> and Boris Veytsman <boris@varphi.com> and Karl Berry <karl@freefriends.org>
COPYRIGHT AND LICENSE
Copyright 2013-2026 Gerhard Gossen, Boris Veytsman, Karl Berry
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.