General Question

PhiNotPi's avatar

How do I accomplish this in Perl (details inside)?

Asked by PhiNotPi (12686points) January 29th, 2011

I need to find a way to expand a hash (or some sort of database). As part of the program, the program generates numbers which need to be stored. I need to find a way so that, when I tell the program to generate another number, the program will make a new entry in the hash/database to enter that number into. If I told the program to make 50 numbers, it should still be able to tell me what the 5th, 12th, etc. numbers were.

Observing members: 0 Composing members: 0

2 Answers

phaedryx's avatar

I don’t know perl, but it sounds like you’re describing an array.

MrItty's avatar

my @numbers;
my $num = get_next_number(); #define this however you want
push @numbers, $num; #add the new $num to the end of the @numbers array
# . . .
print “Which number would you like to retrieve? (1, 2, 3, etc)\n”;
chomp(my $which_num = <STDIN>);
print “Number $which_num = $numbers[$which_num-1]\n”;

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther