I'm trying to execute a query that is stored in a module, but the query has some variables that are read from the main file and is not working.
The variable from the main file is not accessible (its blank) inside the module.
Here is the code:
sql.pm
package sql;
use parent 'Exporter';
our @EXPORT = qw(%query);
our %query = (
one => "SELECT isnull(BusinessEntityID, '') as BusinessEntityID,
isnull(Title, '') as Title,
isnull(FirstName, '') as FirstName,
isnull(LastName, '') as LastName,
isnull(Suffix, '') as Suffix,
isnull(JobTitle, '') as JobTitle
FROM HumanResources.vEmployee
where BusinessEntityID = ".$id."
order by BusinessEntityID"
);
1;
main.pl
use strict;
use warnings;
use sql;
my $id = 273;
my $query_main = "$query{one}";
print $query_main;
This prints the query with where BusinessEntityID = instead of where BusinessEntityID = 273
Thank you!
get_query { my ($id)=@_; %query=...}. Call itmy $query_main=sql::get_query($id);