in reply to Re: Type of arg 1 to splice must be array (not keys)
in thread Type of arg 1 to splice must be array (not keys)

Thats a good solution. The only problem is that I don't know the number of keys. So I can have more or less. Which means I have to rewrite your solution to
my @k = (keys %mh)[0 .. (scalar keys(%my) <= 100 ? scalar keys(%mh) : +100)] ;
Which doesn't look that good anymore. So I prefer 'splice'. Is there a way to convert this 'key' list into an array ?

Replies are listed 'Best First'.
Re^3: Type of arg 1 to splice must be array (not keys)
by JavaFan (Canon) on Dec 14, 2009 at 13:15 UTC
Re^3: Type of arg 1 to splice must be array (not keys)
by ikegami (Patriarch) on Dec 14, 2009 at 15:36 UTC

    Your slice solution is buggy and uses scalar needlessly.

    my $keys = keys(%my) < 100 ? keys(%mh) : 100; my @k = ( keys %mh )[0..$keys-1];
    or
    my $keys = min 100, keys(%mh); my @k = ( keys %mh )[0..$keys-1];

    (List::Util provides min)

    A splice solution:

    my @k = keys %mh; splice( @k, 100 ) if @k > 100;

    You need the conditional to avoid the warning.

    Update: Added fix to OP's slice solution.