I am using a perl package (Biomart), that includes a subroutine called addFilter(). That subroutine needs a couple of arguments, including one that needs to be of the format “nr:nr:nr”
If I use the subroutine as follows, it works fine:
$query->addFilter("chromosomal_region", ["1:1108138:1108138","1:1110294:1110294"]);
However, if I use it like this, it does not work:
my $string = '"1:1108138:1108138","1:1110294:1110294","1:1125105:1125105"';
$query->addFilter("chromosomal_region", ['$string']);
Since there are tens of thousands of those arguments that I construct in a for loop, I really need the second way to work… What could be causing this? I hope someone can help me out, many thanks in advance!
Because you seem to be trying to write in a language that’s not Perl.
'"this","that","another"'isn’t an array, it’s a string. And'$string'doesn’t interpolate or include$stringin any way because it uses single quotes. It just produces a string that starts with a dollar sign and ends with “string”.Something more like what you intend would be:
-or-
And to build it up dynamically, you can simply do
push @things, $valuein a loop or whatever you need.