Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: reordering a stack with little effort

by kvale (Monsignor)
on Mar 11, 2005 at 00:46 UTC ( [id://438481]=note: print w/replies, xml ) Need Help??


in reply to reordering a stack with little effort

In perl, I would create an array of questions, each array element holding a reference to a hash:
my @questions # a question from the Tasmanian Devil push @questions, {id => 1, text => "Why for you want to bury me in the + cold, cold ground?, show => 1}; # etc.
Note here that QUESTION_NUM is just the index in the array plus 1.

Then inserting a question after question 10 is a simple matter of of a splice:

# Maxwell Smart? my $new_q = {id => 9, text => "Shall we use the Cone of Silence?, show + => 1}; splice @questions, 9, 0, $new_q;
For references to other questions, just add a reference => $quest_ref element to the hash.

-Mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://438481]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found