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
From perlvar.html docs:
$/
The input record separator, newline by default. This influences Perl's idea of what a "line" is. Works like awk's RS variable, including treating empty lines as a terminator if set to the null string. (An empty line cannot contain any spaces or tabs.)
If you use $/
, it should always be local.
I personally would do it like this:
my $file = join '',
$file =~ s/.../.../eg;
But you can do it like below, but you must include the /g
modifier.
Look at the >>>
chunks Perl is grabbing. When $/ is set to ''
, it uses a blank line as a record separator.
use strict;
use warnings;
my $num = 0;
{
local $/ = '';
while ()
{
print ">>> '$_'\n\n";
s/(INSERT[\s\S]*?;|DELETE[\s\S]*?;|UPDATE[\s\S]*?;|SELECT[\s\S]*?;)/'\n"/eg;
print;
}
}
__END__