develooper Front page | perl.perl5.porters | Postings from August 2010

keys/values on arrays

Thread Next
From:
H.Merijn Brand
Date:
August 20, 2010 06:41
Subject:
keys/values on arrays
Message ID:
20100820154134.0d710de0@pc09.procura.nl
As of 5.11.0, one can use keys/values on arrays

$ perl -MDP -wle'my@x=("a".."d");delete$x[2];DDumper{array=>\@x,keys=>[keys@x],values=>[values@x]}'
{   array            => [
        'a',
        'b',
        undef,
        'd'
        ],
    keys             => [
        0,
        1,
        2,
        3
        ],
    values           => [
        'a',
        'b',
        undef,
        'd'
        ]
    }

Nice, logical and potentially useful.

How much of a slowdown, if implementable at all, would it be to have
keys return undef for the deleted or sparse keys too? And how useful
would that be?

as in

my @x = 0 .. 10;
 keys @x => 0 ..10

$y[2] = 1;
 keys @y => undef, undef, 2

my @z = 0 .. 4;
delete $x[2];
 keys @z => 0, 1, undef, 3, 4

Note that this would not change any normal array operations, just
the use of keys on the array

-- 
H.Merijn Brand  http://tux.nl      Perl Monger  http://amsterdam.pm.org/
using 5.00307 through 5.12 and porting perl5.13.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/           http://www.test-smoke.org/
http://qa.perl.org      http://www.goldmark.org/jeff/stupid-disclaimers/

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