Please, I have the following line of code to write the header of a file, but I'd like to print each element of the array @order twice side-by-side. For example: $1 $1 $2 $2 $3 $3... in a way that I would have each pair of columns of my output file with the same name.
print(join("\t", "Case_ID", "State", "Ind", "DoB", @order) . "\n");
Can I do something simple or I have to loop over the array to repeat the elements before I print?
Thanks!
Multiply the array element at that given value (index) with a negative number say -1. If a number have appeared once then the value in the array at that index will be negative else it will be positive if it has appeared twice (-1 * -1 = 1). Find the element with positive value and return their index.
Method 1 :Run a loop from index 0 to n and check if (visited[i]==1) then skip that element. Otherwise create a variable count = 1 to keep the count of frequency. Check if(arr[i]==arr[j]), then increment the count by 1 and set visited[j]=1.
You have to loop anyway, but you can use map for syntactic elegance:
# map { $_, $_ } @order
print join("\t", "Case_ID", "State", "Ind", "DoB", map { $_, $_ } @order))
. "\n";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With