Home: Perl Programming Help: Intermediate:
quick question on associative arrays


Nov 6, 2011, 8:48 AM

Views: 1850
quick question on associative arrays


I originally put this in beginners, ~ 100 views with no response.
Hopefully, I can get a response here. I really do need the assistance.

I have ~ 10 associative arrays with data such as:

%Vol_Name = Vol_ID, Vol_Name
%Status = Vol_ID, Status
%Date = Vol_ID, Date

What I would like to do, is loop through the Vol_Name array
and flag all Vol_ID's of the other arrays.

pseudo code:

loop for size of Vol_Name
Get Vol_ID from Vol_Name array
go through all the other arrays, searching for Vol_ID
if found
display data().

How can I accomplish this?



Veteran / Moderator

Nov 7, 2011, 6:33 PM

Views: 1666
Re: [martialartsdrum] quick question on associative arrays

You need to provide more details on what you're doing and what you need to accomplish, but based on what you've posted I can say that you're using the wrong data structure. Instead of 3 separate hashes, you should be using 1 HoH ( hash of hashes).

New User

Nov 7, 2011, 10:44 PM

Views: 1651
Re: [FishMonger] quick question on associative arrays

hey your problem is not descriptive and its not clear , can you specify your problem clearly.... Like
What input you need and what output you expect???



Dec 3, 2011, 1:00 PM

Views: 1539
Re: [martialartsdrum] quick question on associative arrays

Not 100% sure I understand the problem, but I'll try and answer.
Noted that you originally posted in beginner.

# get the keys for the Vol_Name array and loop through them
foreach $volume (keys %Vol_Name)
# $volume will be set to each of the keys

# get the value from the associative arrays
printf ("The value in the Status array for %s is: %s\n", $volume, $Status{$volume});
printf ("The value in the Date array for %s is: %s\n", $volume, $Date{$volume});
# etc...