Return to Snippet

Revision: 3497
at August 2, 2007 15:20 by iblis


Initial Code
#!/usr/bin/perl -w
use strict;
use utf8;
use encoding "utf8";
use Getopt::Std;
use Text::BibTeX;
#
getopt();
our $opt_r;
die "Usage : $0 [-r] source-file dest-file\n" if !defined( $ARGV[1] ) ;
#
my $oldfile = shift;
open BIBFILE1, '<:utf8', $oldfile or die "Problem opening $oldfile\n";
my $newfile = shift;
open BIBFILE2, '>:utf8', $newfile or die "Problem opening $newfile\n";
#
while (my  $entry = new Text::BibTeX::Entry $oldfile, \*BIBFILE1)
{
	next if !$entry->parse_ok;
	my $keywords = $entry->get ('keywords');
	next if !defined($keywords);
#	my $title = $entry->get ('title');
#	print "$title:\n" if (defined($title));
#	print "$keywords\n-->\n";
##
	my $tags;
	if (!$opt_r) {
		my @list = split (",", $keywords);
		foreach (@list) {s/^ //g; s/ $//g; s/ /_/g};
		$tags = join(' ', @list);
	}
	else {
#		print "reverse\n";
		my @list = split (" ", $keywords);
		foreach (@list) {s/_/ /g};
		$tags = join(', ', @list);
	}	 
#	print "/", $tags, "/\n\n";
##	
	$entry->set ('keywords', $tags);
	$entry->print  (\*BIBFILE2);
}

Initial URL

                                

Initial Description
Convert (comma separated) keywords to (space separated) tags in BibTeX files for use in social bibliography sites (bibsonomy.org, citeulike.org)

Initial Title
Convert keywords to tags (and vice versa) in BiBTeX files

Initial Tags
convert

Initial Language
Perl