Hello,
Today I have an array, and I want to reverse and push it, to make a final array become palindromic.
Upd.If initial array has even length, I want to double the length, otherwise I want doubled and -1 length. I've tried this expression:
push @array, reverse @array[ 0 .. $n / 2 - 1 ];
Where $n - is a length of final array (wanted length).
For some test cases:
@arr =
qw(A B C D E)
qw(A B C D)
qw(A B C)
qw(A B)
qw(A)
It outputs:
A B C D E D C B A
A B C D D C B A
A B C B A
A B B A
A A
I would like to get only one 'A' (n = 1) in the last output line. Intuitively it looked like '0 .. 1/2 - 1' is an empty list, however '0 .. -0.5' is being converted to '0 .. 0', so it is a non-empty range, because '..' asks its operands to become integers, i.e. 'int(-0.5)' becomes '0' (opposing to POSIX:floor).
So even ranges '0 .. -0.5' and '0 .. 0.5' are equal.
What expression would you suggest to put into brackets to achieve my goal:
push @array, reverse @array[ EXPR ];