Perl returns hash keys not the same ordered they have been entered I am awareSo you need to use a second structure which will enforce the order you require. Something like this might be what you're looking for:
Actually Perl goes further than not guaranteeing that hash keys will be read out in the same order they've been written in. As the second paragraph in my man page for the 'keys' builtin reads:foreach my $key (qw(name specialization age)) { print "enter your $key\n"; print FILE "$key: " ,$info{'$key'}=<>, "\n"; }
The keys are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the "values" or "each" function produces (given that the hash has not been modified). Since Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see "Algorithmic Complexity Attacks" in perlsec).So if you're running your unmodified code in version 5.8.1 or later different runs will give randomly generated order for the questions. But at least with three input values, you'll get the order you want 1 in 6 times!
In reply to Re: a dynamic program???
by dec
in thread a dynamic program???
by biohisham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |