How do I use Perl and Regular Expressions to convert a SQL document to ColdFusion script?

后端 未结 3 1773
陌清茗
陌清茗 2021-01-27 11:49

I need to convert a document of SQL statements to a ColdFusion document. I only have a little experience with Regular Expressions and I am Perl super-newb (I just taught myself

3条回答
  •  萌比男神i
    2021-01-27 12:16

    You can take advantage of the fact that the individual sql statements in your input file are terminated by a semi-colon character. Set the record input separator to a semi-colon $/ = ';'in your perl script and then it will read one complete sql statement on each read of STDIN, regardless how many actual lines it spans.

    #!/usr/bin/perl -w                                                                                                                                                                                                                                                                          
    
    use strict;
    
    $/ = ';';
    
    my $num = 0;
    while (my $sql = <>) {
      $sql =~ s/^\s+//;
      printf "\n" if $sql;
    }
    

提交回复
热议问题