Front page | perl.perl5.porters |
Postings from July 2001
Re: ${^Index}
Thread Previous
|
Thread Next
From:
Robin Barker
Date:
July 18, 2001 01:08
Subject:
Re: ${^Index}
Message ID:
200107180808.JAA10657@tempest.npl.co.uk
>
>
> |> What about syntactic sugar?
> |>
> |> foreach $elt (@array) [$i] {
> |> }
>
> This type of thing seems much nicer to me, since it doesn't change anything
> that doesn't use it. It *is* syntatic sugar, but sugar I have often wished
> for, just to keep things tidier.
>
> I would, though, like to see the iterator variable appear earlier. Maybe
> something like one of:
>
> A) for $elt/$i (list) { }
>
> for my $elt / my $i (list) { }
>
> B) for $elt counter $i (list) { }
>
> for my $elt counter my $i (list) { }
>
> C) for $elt [$i] (list) { }
> for my $elt [$i] (list) { }
> # $i is an auto-lexical variable in this case?
>
I think a clean solution is to extend C<each> to arrays,
returning (index,value) in order for the elements of the array.
while( my($i,$elt) = each list) { }
Robin
--
Robin Barker | Email: Robin.Barker@npl.co.uk
CMSC, Building 10, | Phone: +44 (0) 20 8943 7090
National Physical Laboratory, | Fax: +44 (0) 20 8977 7091
Teddington, Middlesex, UK. TW11 OLW | WWW: http://www.npl.co.uk
Thread Previous
|
Thread Next