Can anyone point me inthe right direction, on how to get variable names stored in __DATA__ to be evaluated ?

I have some largish scripts with embedded SQL statements which are ugly. My idea is to store them at the end of the program under __DATA__, parse this, and then refer to them in my code.
The parser module works fine, but the final string contains
WHERE date = "$today_date"
instead of
WHERE date = "2003-09-22"


any ideas ?

Martin


#!/usr/local/bin/perl use strict; use warnings; use some::Module

my $today_date = '2003-09-22';
my %sql_code = parse_sqldata(\*DATA);
foreach my $sql_line (keys %sql_code) {
       print "SQL name => $sql_line\n";
       print "$sql_code{$sql_line}\n";
}


__DATA__ *load_this SELECT this,that FROM my_table WHERE date = "$today_date" *load_that SELECT this,that FROM other_my_table WHERE date = "$today_date"



some_module contains....
sub parse_sqldata {
       my ($data_ref) = @_;
       my (%sql, $found, $sql_code);

while(<$data_ref>) {
chomp();
next if (/^#/);
if (/^\*(\w+)$/) {
if (defined $found) {
$sql_code =~ s/\n$//; #remove last EOL character
$sql_code =~ s/\t/ /g; #replace tabs with spaces
$sql{$found} = $sql_code;
$found = $sql_code = '';
}
$found = $1;
} else {
$sql_code .= "$_\n";
}
}
continue { # process the last sql statement after the read has finished
$sql_code =~ s/\n$//;
$sql_code =~ s/\t/ /g;
$sql{$found} = $sql_code;
}
return(%sql);
}


_________________________________________________________________
Sign-up for a FREE BT Broadband connection today! http://www.msn.co.uk/specials/btbroadband





Reply via email to