#!/usr/bin/perl # Open file $file = $ARGV[0]; open(FH, '<', $file); @raw_data = ; 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; }