http://www.perlmonks.org?node_id=619969

monkfan has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Do you guys happen to know if there is existing Perl implementation for converting BIBITEM entry like this:
\bibitem[Ao {\it et~al}., 2004]{AGKM04} Ao, W. {\it et~al.} (2001) Som +e long title 1, {\it Science}, {\bf 305}, 1743-1746. \bibitem[Bailey and Elkan, 1995]{BE95} Bailey, T. Elkan, C. (1995) S +ome long title 2 {\it Machine Learning}, {\bf 21}, 51-80.
Into BIBTEX entry like this:
@article{AGKM04, author = {Ao, W and \ {\it et~al.}}, title = {Some long title 1}, journal = {Science}, year = {2004}, volume= {305}, pages = {1743-1746}, } @article{BE95, author = {Bailey, T and Elkan, C.}, title = {Some long title 2}, journal = {Machine Learning}, year = {1995}, volume= {21}, pages = {51-80}, }

Regards,
Edward

Replies are listed 'Best First'.
Re: Converting Bibitem into Bibtex Entry with Perl
by andreas1234567 (Vicar) on Jun 08, 2007 at 07:57 UTC
    Perhaps Text::BibTeX could be useful?

    Update:Try the Tex2bib script on this site.

    --
    print map{chr}unpack(q{A3}x24,q{074117115116032097110111116104101114032080101114108032104097099107101114})
Re: Converting Bibitem into Bibtex Entry with Perl
by Corion (Patriarch) on Jun 08, 2007 at 07:21 UTC

    What have you tried so far? I'd simply parse out the information with a regular expression (untested):

    use strict; for my $item (<DATA>) { chomp $item; if ($item !~ /^\\bibitem\[.*?\] # skip the command and optional +argument \{([A-Z\d]+)\] # extract the bibliography item, + all caps letters \s*(.*?) # extract the author list \((\d{4})\) # extract the year (.*?) # extract the publication title \{\\it\s(.*?)\}, # extract the category \s*\{\\bf\s(\d+)\},# extract the volume \s*(\d+-\d+) # extract the page numbers \. # a dot at the end /x) { print "%% Ignoring weird bibliography item: >$item<\n"; next; }; printf <<'TEX',$1,$2,$3,... @article{%s, ... TEX }; __DATA__ \bibitem[Ao {\it et~al}., 2004]{AGKM04} Ao, W. {\it et~al.} (2001) Som +e long title 1, {\it Science}, {\bf 305}, 1743-1746. \bibitem[Bailey and Elkan, 1995]{BE95} Bailey, T. Elkan, C. (1995) Som +e long title 2 {\it Machine Learning}, {\bf 21}, 51-80.