Raydot
asked on
Scalar to command, arrays in hashes?
I want to store a bunch of arrays, and then store a single array list with all of the other arrays inside. So:
@arrayLists = ("dog","cat","rat");
@dog = ("fido", "rex", "king");
@cat = ("tabby", "Kitty", "Morris");
@rat = ("Ratbert", "Sam", "Rudy");
Is there a way to retrieve the values from dog, cat, and rat, by using the values in arraylists?
Also, could I store this all in a single hash?
%masterList = (dog => @dog, cat => ("tabby","rex","king") ...etc for rat)
How would I retrieve these values?
There's gotta be a way...
Raydot.
@arrayLists = ("dog","cat","rat");
@dog = ("fido", "rex", "king");
@cat = ("tabby", "Kitty", "Morris");
@rat = ("Ratbert", "Sam", "Rudy");
Is there a way to retrieve the values from dog, cat, and rat, by using the values in arraylists?
Also, could I store this all in a single hash?
%masterList = (dog => @dog, cat => ("tabby","rex","king") ...etc for rat)
How would I retrieve these values?
There's gotta be a way...
Raydot.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this. with this you dont even need the masterlist hash!!
#!/usr/local/bin/perl
@arrayLists = ("dog","cat","rat");
@dog = ("fido", "rex", "king");
@cat = ("tabby", "Kitty", "Morris");
@rat = ("Ratbert", "Sam", "Rudy");
#%masterList = (dog => @dog, cat => @cat rat => @rat)
foreach $arr (@arrayLists){
foreach(@$arr){
print $_,"\t";
}
print "\n";
}
#!/usr/local/bin/perl
@arrayLists = ("dog","cat","rat");
@dog = ("fido", "rex", "king");
@cat = ("tabby", "Kitty", "Morris");
@rat = ("Ratbert", "Sam", "Rudy");
#%masterList = (dog => @dog, cat => @cat rat => @rat)
foreach $arr (@arrayLists){
foreach(@$arr){
print $_,"\t";
}
print "\n";
}
%masterList = map{$_,\@{$_}} @arrayLists;
were you able to check the comments that were offered?
let us know :)
let us know :)
ASKER
You guys are brilliant. While ozo and man went above and beyond, RobW did answer first. Thanks!
%masterList=(
dog => ["fido","rex","king"],
cat => ["tabby","fluffy","princes
);
print "My third dog is $masterList{'dog'}[2]\n";
would print
My third dog is king