Created
November 23, 2016 07:27
-
-
Save craigiansmith/74d487bf0f50b8abe97854f07850c7a5 to your computer and use it in GitHub Desktop.
Revisions
-
dashaxiong created this gist
Nov 23, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/usr/bin/perl # Open file $file = $ARGV[0]; open(FH, '<', $file); @raw_data = <FH>; close(FH); # Create array to store all jasper vars found @vars = (); # Search for Jasper vars like $P{word} or $P!{word} foreach $line (@raw_data) { if($line =~ /\$P\!?\{([^}]*)\}/) { push (@vars, lc $1); } } # Open file for writing to open(FH, '>', "$file.new"); # Make sure array of variables only has distinct entries my %hash = map { $_, 1} @vars; my @unique = keys %hash; # Prepend set statements to beginning of file # such as "SET @word = '';" for each word foreach $var (@unique) { print FH "SET \@$var = '';\n"; } # Substitute mysql vars in place of the Jasper vars i.e. @word foreach $line (@raw_data) { $line =~ s/\$P\!?\{([^}]*)\}/\@\L$1/g; print FH $line; }