Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameter to perl qw[]?

Tags:

perl

I am customizing an open source Perl script for some db backup. I don't have much knowledge in Perl. Can someone tell me how will i pass a parameter to qw[]?

for example the original code is like this

@selected_databases  = qw[testdb1 testdb2 testdb3];

i want to convert it to something like below

$_dblist = "testdb1 testdb2 testdb3";
@selected_databases  = qw[$_dblist];

but it is not working. Can someone tell me how will I pass a variable to qw[]?

like image 559
codlib Avatar asked Dec 22 '22 02:12

codlib


1 Answers

qw does not support interpolation. As per the perl-doc. As such, you cannot do that, it will not work. To achieve what you are looking to do, use the split function.

$_dblist = "testdb1 testdb2 testdb3";
@selected = split(' ', $_dblist);
like image 188
zellio Avatar answered Dec 31 '22 01:12

zellio