develooper Front page | perl.perl5.porters | Postings from January 2014

Re: Range idea

Thread Previous | Thread Next
From:
Dr.Ruud
Date:
January 23, 2014 14:06
Subject:
Re: Range idea
Message ID:
20140123140616.14859.qmail@lists-nntp.develooper.com
On 2014-01-23 13:25, H.Merijn Brand wrote:

> Wanting to take all the elements from a list starting at position x to
> the end is pretty hard when the list is dynamic, so $#list cannot be
> used, nor can index -1

Do you mean a iterator, or do you want to receive all elements in one 
call? Shallow copies, or aliases?


> $ perl -wE'say for [qw( a b c d )]->[2 ..]'

Maybe get a contextual $# for that:

perl -wE'
   $# = 3;
   say for qw( a b c d )[2 .. $#];
'
$# is no longer supported at -e line 2.
$# is no longer supported at -e line 3.
c
d


Or even:

perl -wE'
   say for qw( a b c d )[2 .. $#<];
'
$# is no longer supported at -e line 2.
syntax error at -e line 2, near "<]"
Execution of -e aborted due to compilation errors.

-- 
Ruud


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About