in reply to question regarding slices
Consider the following code:
my @array = qw/this that the other/; local $, = ", "; print @array[1..$#array], "\n"; __OUTPUT__ that, the, other
An unnamed true list (one that isn't held within a scalar in any way, nor referenced by an array-ref) can't be indexed in such a way as to construct a 0..end-of-list, but you do have a couple of other options.
my $last_item = (this, that, the, other)[-1];
Or the more useful...
my $list = [qw/this that the other/]; local $, = ", "; print @{$list}[0..$#{$list}];
This last alternative uses an anonymous list referred to by an array-ref scalar.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: question regarding slices
by Grygonos (Chaplain) on Nov 06, 2003 at 18:36 UTC |