How to pop from an array inside a hashref?


Brain getting foggy on this one. I wanted to take my dice game from using rand() to using a list of random values from I was able to retrieve the values just fine, I'm just hung up on the syntax to pop from the list.

Here's my function that's giving me fits:

sub roll_d
  return (pop($$dice_stack{@_[0]}));
  # Original code:
  #return (int(rand @_[0]) + 1);

Where $dice_stack is a pointer to a hash where the key is the dice type ('6' for d6, '20' for d20), and the value is an array of integers between 1 and the dice type.


Try dereferencing the array first:


$$dice_stack{@_[0]} - aka $dice_stack-

By : DVK

This video can help you solving your question :)
By: admin