Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: reordering a stack with little effort

by kvale (Monsignor)
on Mar 11, 2005 at 00:46 UTC ( #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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2022-05-16 08:55 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (62 votes). Check out past polls.