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

Try it using a list slice:

my @k = ( keys %mh )[ 0 .. 99 ];

Replies are listed 'Best First'.
Re^2: Type of arg 1 to splice must be array (not keys)
by jeanluca (Deacon) on Dec 14, 2009 at 13:11 UTC
    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 ?

      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.