I have an array @genotypes = "TT AG TT AG...."
and want to add a spike to it (e.g. 20 x TT) to make a new array.
I can obviously push
"TT" into the array 20 times - but is there a simpler way of doing this? (ie. not @newarray = push @genotypes ("TT", "TT", "TT",......20 times!);
The push() function pushes the new value or values onto the right side of the array and increases the elements. ); push @myNames, 'Moe'; You can also push multiple values onto the array directly ...
push() function in Perl is used to push a list of values onto the end of the array.
PERLServer Side ProgrammingProgramming Scripts. You can also extract a "slice" from an array - that is, you can select more than one item from an array in order to produce another array.
@newlist = (@genotypes, ('TT') x 20);
Yes, it is an x
.
See Multiplicative Operators in perldoc perlop.
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