rsFalse has asked for the wisdom of the Perl Monks concerning the following question:
Where $n - is a length of final array (wanted length). For some test cases: @arr =push @array, reverse @array[ 0 .. $n / 2 - 1 ];
It outputs:qw(A B C D E) qw(A B C D) qw(A B C) qw(A B) qw(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).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
push @array, reverse @array[ EXPR ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help with range expression ('0 .. -0.5' === '0 .. 0.5')
by poj (Abbot) on Feb 23, 2019 at 18:49 UTC | |
|
Re: Need help with range expression ('0 .. -0.5' === '0 .. 0.5')
by vr (Curate) on Feb 23, 2019 at 19:09 UTC | |
by BillKSmith (Monsignor) on Feb 24, 2019 at 04:41 UTC | |
by vr (Curate) on Feb 24, 2019 at 06:36 UTC | |
by BillKSmith (Monsignor) on Feb 24, 2019 at 14:00 UTC | |
|
Re: Need help with range expression ('0 .. -0.5' === '0 .. 0.5')
by 1nickt (Canon) on Feb 23, 2019 at 18:48 UTC | |
|
Re: [SOLVED]: Need help with range expression ('0 .. -0.5' === '0 .. 0.5')
by rsFalse (Chaplain) on Feb 24, 2019 at 21:26 UTC | |
by AnomalousMonk (Archbishop) on Feb 24, 2019 at 22:17 UTC |