Txt2flp.pl
From Wiki2
#!/usr/bin/perl -w #from tests dir - usage: perl txt2flp.pl rootname term# #takes questions in edit page and turns them into csv file for import into flipchart #get command line args for (root of)filename and dir $di = "1enl, 2ism, 3war, 4bip"; $d = $ARGV[1]; $di =~ m/($d\w*)/; #regex for finding the word that starts with what's in $d $dir = $1; $n = $ARGV[0]; #$n =~ m/(.*)\./; #regex to get body of filename $nam = $n; $inq = $dir . "/t/" . $nam . ".txt"; $ina = $dir . "/t/" . $nam . ".ans"; $ouc = ">". $dir . "/c/" . $nam . ".csv"; open (INA, "$ina") || die "no stinking anwers"; open (IN, "$inq") || die "what questions?"; open (GMA, "$ouc") ; @ca = <INA> ; $a = ""; $qo = ""; $c = 0; $cnt = -1; while (<IN>) { s/"/'/g; #substitutes single quotez for doubles if($_ =~ m/##(.*)/) { #regex match for ## plus everything $a = $a . ", \"" . $1 . "\""; $c++ ; } else { chomp; $qn = substr($_,1); if (length $qo > 0) { $cor = $ca[$cnt]; chomp($cor); $ou = "\"" . $qo . "\",". $c . "," . $cor . $a . "," x (7-$c) . " \n" ; print $ou; print GMA $ou; $cnt++; } $qo = $qn; $a = ""; $c = 0; } } $cor = $ca[$cnt]; chomp($cor); $ou = "\"" . $qn . "\",". $c . "," . $cor .$a . "," x (7-$c) . " \n" ; print $ou; print GMA $ou; close IN; close GMA; close INA;