I have an array like the following:
my @a = ('%d %d', 10, 20);
I'd like to use the elements of this array as the arguments for a function.
If I just try using it directly, it gets interpreted in scalar context:
say sprintf(@a); #=> 3
I also tried this, which didn't work of course:
@_ = @a; say sprintf; #=> Not enough arguments...
The splat syntax that some languages have doesn't work here either (I'm just taking wild guesses at this point):
say sprintf(*@a); #=> (error)
The same problems occur with other builtin functions, such as join
.
Is there any way to take an arbitrary array (of unknown length) and an arbitrary function and call the function using the elements of the array as arguments for the function? If so, how?