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
    Should be written? I've never seen a die like that :)
    Update: I understand the spec this way:
    while ($n = int (rand 6) ){ print 6-$n,"\n"; $count++; } print "6\nTried ",1+$count," times.\n";