Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. sub build_script
  2. {
  3. my $cols = shift;
  4.  
  5. foreach my $col (@$cols)
  6. {
  7. print($col . ",\n");
  8. }
  9. }
  10.  
  11. sub parse_source_file
  12. {
  13. my $filename = shift;
  14. my $table_name = shift;
  15.  
  16. my $file;
  17. my $line;
  18. my $cols = ();
  19.  
  20. if (!open($file, "<", $filename))
  21. {
  22. print "file not found\n";
  23. return;
  24. }
  25.  
  26. while ($line = <$file>)
  27. {
  28. $line =~ s/\W+$//;
  29. my @fields = split(',', $line);
  30. if ($fields[0] eq $table_name)
  31. {
  32. push(@cols, $fields[1]);
  33. }
  34. }
  35.  
  36. close($file);
  37. return \@cols;
  38. }
  39.  
  40. sub main
  41. {
  42. my $db = uc($ARGV[0]);
  43. my $table = uc($ARGV[1]);
  44. my $source = $ARGV[2];
  45.  
  46. my $cols = parse_source_file($source, $table);
  47. build_script($cols);
  48. }
  49.  
  50. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement