Permalink
Browse files

Whitespace and style fixups.

For #145
  • Loading branch information...
1 parent fb289ff commit 591af41fa816fdfef34b71275289e859c63019db @schwern schwern committed Nov 29, 2011
Showing with 25 additions and 22 deletions.
  1. +10 −7 lib/perl5i/2/ARRAY.pm
  2. +15 −15 t/pick.t
View
@@ -50,24 +50,27 @@ method as_hash{
}
-method pick ( $num ){
+method pick ( $num ) {
my @result = ();
my %used = ();
- for(my $i =0; $i<$num && $i<@$self; $i++){
- my $rand = int(rand(@$self));
- if(!(exists $used{$rand})){
- @result->push(@$self[$rand]);
+
+ for(my $i = 0; $i < $num && $i < @$self; $i++){
+ my $rand = int rand @$self;
+ if( !exists $used{$rand} ) {
+ @result->push( @$self[$rand] );
$used{$rand} = 1;
- }else{
+ }
+ else {
$i--;
}
}
+
return wantarray ? @result : \@result;
}
method pick_one() {
- return @$self[int(rand(@$self))];
+ return @$self[int rand @$self];
}
View
@@ -1,19 +1,19 @@
#!/usr/bin/perl
- use perl5i::latest;
- use Test::More;
-
- note 'pick method'; {
- my @array = qw(a b c d e f g h i);
- my @rand = @array->pick(5);
- my $size = @rand;
- is $size, 5;
- @rand = @array->pick(100);
- $size = @rand;
- is $size, 9;
- @rand = @array->pick(0);
- $size=@rand;
- is $size, 0;
+use perl5i::latest;
+use Test::More;
+
+note 'pick method'; {
+ my @array = qw(a b c d e f g h i);
+
+ my @rand = @array->pick(5);
+ is @rand, 5;
+
+ @rand = @array->pick(100);
+ is @rand, 9;
+
+ @rand = @array->pick(0);
+ is @rand, 0;
}
- done_testing(3);
+done_testing(3);

0 comments on commit 591af41

Please sign in to comment.