I've seen questions for the equivalent of PHP's compact
function in other languages but not Perl so forgive me if this is a repeat to something I missed. If you are unfamiliar with this function here is what I'm looking for.
Given variables:
my $one = "1";
my $two = "2";
my $three = "3";
#using compact as example here since this function doesn't exist in perl
my $array = compact("one","two","three");
Then dumping $array would give:
[
one => "1,
two => "2",
three => "3"
]
From the PHP documentation for compact
:
Creates an array containing variables and their values.
For each of these,
compact()
looks for a variable with that name in the current symbol table and adds it to the output array such that the variable name becomes the key and the contents of the variable become the value for that key.
I am specifically working with version 5.8.8. Forgive me if some of my syntax is off. My background is PHP.