Bug?

Matt Lawrence matt.lawrence at virgin.net
Mon Dec 9 11:40:47 GMT 2013


On 09/12/13 11:23, Kieren Diment wrote:
> In a short subroutine, this:
>
>      use List::Util qw/shuffle/;
>      my @list = @{$self->answer_list_orig_order};
>      @list = shuffle @list if $self->random_order;
>      return \@list;
>
> does what's expected.  Returns the shuffled list.
>
> This:
>
> use List::Util qw/shuffle/;
> my @list = @{$self->answer_list_orig_order};
> @list = shuffle @list if $self->random_order;
> return \@list
>
> returns the list unshuffled.
>
> What's up with that?

So the difference is just the semicolon at the end? Works for me either way.

$ perl -Mstrict -wE 'sub foo { my $self = shift; use List::Util qw/shuffle/;
my @list = @{$self->answer_list_orig_order};
@list = shuffle @list if $self->random_order;
return \@list;} sub answer_list_orig_order { [1 .. 10] } sub 
random_order { 1 } say for @{ main->foo }
'
5
10
4
2
9
3
7
1
8
6

$ perl -Mstrict -wE 'sub foo { my $self = shift; use List::Util qw/shuffle/;
my @list = @{$self->answer_list_orig_order};
@list = shuffle @list if $self->random_order;
return \@list} sub answer_list_orig_order { [1 .. 10] } sub random_order 
{ 1 } say for @{ main->foo }
'
2
6
9
10
5
4
3
8
7
1

Matt


More information about the london.pm mailing list