|go ahead... be a heretic|
Last index use in array sliceby ltp (Beadle)
|on Dec 03, 2012 at 03:27 UTC||Need Help??|
ltp has asked for the
wisdom of the Perl Monks concerning the following question:
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.