in reply to Re^2: Type of arg 1 to splice must be array (not keys)
in thread Type of arg 1 to splice must be array (not keys)
Your slice solution is buggy and uses scalar needlessly.
ormy $keys = keys(%my) < 100 ? keys(%mh) : 100; my @k = ( keys %mh )[0..$keys-1];
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.
|
|---|