jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I need to do the following:$result = mySub(@inpdb, qw(val1 val2) ) ; The problem I have now is that I have val1 and val2 inside an array @val I've tried the following, which didn't work!:
$r = &mySub(@inpbd, @val) ; $dummy = "@val" ; $r = &mySub(@inpbd, qw($dummy)) ;
I also do not know how many vals are available, so I cannot do:
@r = &mySub(@inpDB, "$val1","$val2","$val3");
which does work!!
Any suggestions ?

Thanks a lot
Luca

Replies are listed 'Best First'.
Re: qw and $vars or @vars
by g0n (Priest) on Jan 26, 2006 at 11:52 UTC
    From your description of your problem, you want to pass your sub an array, made up of two arrays joined together?

    The first line of your example should work. Try this:

    my @array1 = qw (one two three); my @array2 = qw (four five six); doprint(@array1,@array2); sub doprint { for (@_) { print "$_\n"; } }

    Result:

    one two three four five six

    --------------------------------------------------------------

    "If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."

    John Brunner, "The Shockwave Rider".

Re: qw and $vars or @vars
by jeanluca (Deacon) on Jan 26, 2006 at 12:05 UTC
    Ooooh, now it works, thanks, I didn't understand qw very well :)