I need to write an union function using Perl, and what I did is here, questions is followed by code.
sub union
{
my @array1 = qw/a b c d/;
my @array2 = qw/a f g h/;
my %myunion = ();
@myunion{ @array1, @array2 } = (1) x ( @array1 + @array2 );
@myunion = keys %myunion;
return @myunion;
#if(){
# return @myunion;
#}
#else{
# return join ',', @myunion;
#}
}
my @uString = union( [ 1, 2, 3 ], [ 2, 3, 4 ] );
my @uList = union( [ 1, 2, 3 ], [ 2, 3, 4 ] );
print "$uString\n"
print "@uList\n";
So without my command part, my out put is a b c d f g h in random order, but I want to make them as 1 2 3 4 in random order as what I write as input in my @uList. Also I need to check whether the caller requires a list, if it is it will return 1 2 3 4in random order, otherwise, it will return a comman-seperate string of the union which should be 1,2,3,4 in random order. So I want to know what should I do in the condition part of the if else statement.