I want to be able to export a set of variables that I create on the fly, but am having trouble working out the syntax. Below is an example of the kind of thing I want to do
package gen_var;
use base 'Exporter';
my @exported_symbols;
my @variables = qw(one two three);
my $counter = 1;
our @EXPORT_OK;
foreach my $variable (@variables) {
eval "our \$$variable = $counter; push \@exported_symbols, \$$varia
+ble";
$counter++;
}
my $export_vars = join(', ', @exported_symbols);
eval "\@EXPORT_OK = ($export_vars)";
1;
then in another piece of code:
use gen_var($one);
print $one;
I realise some purists may bristle at this kind of code, but now that I've had a crack at writing it, I'm interested in finding out how to get it to work