Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable variable names?

Status
Not open for further replies.

emilybartholomew

Technical User
Aug 3, 2001
82
0
0
US
Hi -

I searched around this forum & wasn't able to find what I was looking for. I am writing a script that loops through a variable number of Users who answer a survey & creates hashes for each of the Users that holds how they answered each question. I want to have hash names like %user1, %user2, etc., with the digit portion of the name variable. I tried things like
%user$UserID, %user'$UserID', %user.'$UserID'
but those didn't work. I feel like there's some easy answer to this I just can't put my finger on.

Thanks-
Emily
 
You could use something like:
Code:
${ "user" . $digit }{'Key'}= "Value";
to dynamically build the hash name. This will not work if you are using strict "refs". I would just build a multilevel hash with the user as the hash key and each user's survey as an anonymous hash. eg:
Code:
%survey = {
  'user1' => {
     'q1' => 'a1',
     'q2' => 'a2'
  },
  'user2' => {
     'q1' => 'a1-2',
     'q2' => 'a2-2'
  },
  ...
}
Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top