#!/usr/bin/perl -w use strict; use warnings; use RTF::Writer; use Unicode::Subscript ':all'; use Text::CSV; #use Unicode::Subscript qw(subscript superscript); if(@ARGV != 2) { print STDERR "Usage: authorship_APP.pl input(.csv) output(.rtf)\n"; exit(0); } my ($inf, $outf)=@ARGV; my $all_affi; my %hash; my @all_name; my $count=1; my @rows; my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<", $inf or die "$inf: $!"; while ( my $row = $csv->getline( $fh ) ) { if($row->[0]=~/^\d/){ my @a_num; for(my $i=3; $i<=7; $i++){ if($row->[$i]=~/\w/){ my $tmp=$row->[$i]; if(! exists $hash{$tmp}){ $hash{$tmp}=$count; push(@a_num, $hash{$tmp}); $all_affi.=$count.$tmp."\. "; $count++; } }else{ last; } } my $a_num=join"\+", @a_num; if($row->[2]=~/\w/){ push(@all_name, "$row->[1] $row->[2]".superscript($a_num)); }elsif($row->[1]=~/\w/){ push(@all_name, "$row->[1]".superscript($a_num)); }else{ print STDERR "Error! Wrong first name for this row:\n$row\n"; exit; } } } $csv->eof or $csv->error_diag(); close $fh; my $all_name=join", ", @all_name; print STDERR "There are ". scalar(@all_name)." authors and ".scalar(keys %hash)." affiliations in this list.\n"; my $final= "$all_name\n\n$all_affi\n"; #my $test='This algorithm is O(n' . superscript(3) . ')'; my $rtf = RTF::Writer->new_to_file($outf); $rtf->prolog( 'title' => "Greetings, Naomi" ); $rtf->number_pages; $rtf->paragraph( $final ); $rtf->close;