in reply to Perl script newbie need help !!!
The program I think you are asking for:
#!/usr/bin/perl use warnings; use strict; use constant UPPER_LIMIT => 6; my ( @numbers, $count ); while ( @numbers < UPPER_LIMIT ) { my $guess = int 1 + rand UPPER_LIMIT; push @numbers, $guess unless grep $_ == $guess, @numbers; ++$count; } print map( "$_\n", @numbers ), "How many times to get to ", UPPER_LIMIT, " is $count\n"; __END__
How the program should really be written:
#!/usr/bin/perl use warnings; use strict; use List::Util qw/ shuffle /; use constant UPPER_LIMIT => 6; my @numbers = shuffle 1 .. UPPER_LIMIT; print map( "$_\n", @numbers ), "How many times to get to ", UPPER_LIMIT, " always ONE\n"; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl script newbie need help !!!
by choroba (Cardinal) on Nov 11, 2010 at 18:36 UTC |