Heres how I would code what you have already:
#!/usr/bin/perl
use strict;
use warnings;
#use BeginPerlBioinfo;
srand($$|time);
my $data = {
'Homo Sapien' => {
Chromosomes => {
(map { $_ => {Contigs => 25} } (1..22, qw/X Y/)), # Auto g
+en
1 => {Contigs => 30}, # Override these two..
2 => {Contigs => 28},
},
},
};
# This program will download the sequences from a given organism
my $organism = ask('Which organism would you like to download the '.
'sequences from?');
#my $organism = 'Homo Sapien';
my $number = ask("How many sequences do you want to generate?");
#my $number = 10;
if (exists $data->{$organism})
{
for (1..$number)
{
my $chromosome = random_element(keys%{$data->{$organism}{Chrom
+osomes}});
print " Chromosome '$chromosome' \n";
my $contig = random_element(
(1..$data->{$organism}{Chromosomes}{$chromosome}{
+Contigs})
);
print " Contig '$contig' \n";
}
}
else
{
print "I don't know anything about organism: '$organism'\n";
}
exit;
################
#
##############
# ask
#
# Sub which asks a given question and returns the chomped input from t
+he user
sub ask {
my $query = shift;
print $query, ":\n";
my $answer = <STDIN>;
chomp $answer;
return $answer;
}
# random_element
#
# Sub routine that picks up random element from a given array
sub random_element{
# I think there's a problem with the randomness of this
return $_[int rand(0+@_)];
}