Just use a list snippet :
#!/usr/bin/perl use strict; my @list = map { int(rand*10) } 1..10; print join(', ', @list[0..4]) . "\n";
Also, use strict , without exception, if you really don't like spending too much time looking for subtle errors.
source share