develooper Front page | perl.perl5.porters | Postings from March 2021

Re: undoing of auto-deref removal

Thread Previous | Thread Next
From:
Uri Guttman
Date:
March 5, 2021 01:15
Subject:
Re: undoing of auto-deref removal
Message ID:
2755ccf2-4145-1b6d-92cf-98fd7a281591@stemsystems.com
On 3/3/21 9:14 AM, shmem wrote:
>
>
> 5. Making "keys", "values" and "each" work on arrays is a spectacular
>    braindead decision. When has this been called for? based on what
>    rationale? In my book, "keys" refers to the keys of an associative
>    array, "values" to the values only, and "each" to tuples comprised
>    of both of them. Nothing to do with arrays, whose entries are
>    accessed via indices, and if flattened give a list.

making those 'work' on scalars that are auto-derefed was braindead. 
making them work on real arrays is actually pretty useful. i have had 
need to get the indices and values of an array (there are many useful 
needs for those indices) and each does that. otherwise you need to do 
you own indexing and accessing the value in the array

foreach (my $i = 0 ; $i++ ; $i < $#array ) {
     my $val = $array[$i] ;

while( my( $i, $val ) = each @array ) {

and it is also cleaner with an array ref.

and no need to know to use $#array vs @array.

keys and values are of pretty low need for arrays. they added them for 
consistancy when auto-deref was done.

uri


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