ltp has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks,
I know I'm doing something very silly here that has likely been asked and answered countless times before, but my meditation this Monday morning lacks insight.
I'd like to take a slice of an array returned from a method without first assigning the array. Furthermore I'd like the slice to be from an abritrary index to the last index in the array. For example:
my @slice = ( split /\n/, $object->get_array )[$index .. -1];However, on attempting this I find that the slice contains no values - this makes some sense as there is no overlapping region in the range bounded by the indexes (the region counting forward in the array from index a to the region counting back from the end of the array to index b).(Apologies for the fuzzy language here as I wasn;t sure how to word the terms).
Unfortunately, when I attempt to use $# as the second index for the array slice, I get the warning:
$# is no longer supported at -e line 1.I do however get a slice containing a single value (the first value of the array). I know I'm clearly overlooking something here, but what? It would be trivial to change this line to first assign the array returned by the split and then use ~~@array as the index of the last value, but this has me trumped.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Last index use in array slice
by GrandFather (Saint) on Dec 03, 2012 at 03:33 UTC | |
by ltp (Beadle) on Dec 03, 2012 at 03:52 UTC | |
|
Re: Last index use in array slice
by LanX (Saint) on Dec 03, 2012 at 03:37 UTC | |
|
Re: Last index use in array slice
by ColonelPanic (Friar) on Dec 03, 2012 at 09:23 UTC | |
by bart (Canon) on Dec 03, 2012 at 13:15 UTC | |
by ColonelPanic (Friar) on Dec 03, 2012 at 13:29 UTC | |
|
Re: Last index use in array slice
by LanX (Saint) on Dec 03, 2012 at 12:41 UTC |