format.pl 920 B

123456789101112131415161718192021222324252627282930313233343536
  1. #! perl
  2. open (FILE, "TRAININGFINAL.csv") or die "couldn't open the file\n";
  3. $line_length = 60;
  4. while (<FILE>)
  5. {
  6. my ($number, $description) = split (/,/, $_, 2);
  7. $number =~ s/\s//g;
  8. if ($number ne "")
  9. {
  10. print "\t\t// $number\n";
  11. $description =~ s/^"(.*)"$/$1/;
  12. $description =~ s/"/'/g;
  13. $description =~ s/\n$//g;
  14. $description = "\"$description\"";
  15. my $printable_description = "";
  16. while (length ($description) > $line_length)
  17. {
  18. my $tmp_length = $line_length;
  19. my $tmp_string = substr ($description, 0, $tmp_length);
  20. while ($tmp_string =~ /\S$/)
  21. {
  22. $tmp_length--;
  23. $tmp_string = substr ($description, 0, $tmp_length);
  24. }
  25. $printable_description = "$printable_description\t\t// $tmp_string\n";
  26. $description = substr ($description, $tmp_length);
  27. }
  28. $printable_description = "$printable_description\t\t// $description\n\n";
  29. print "$printable_description";
  30. }
  31. }
  32. close (FILE);