Ntav has asked for the wisdom of the Perl Monks concerning the following question:
Cases 1& 2 work, case 3 can be made to work with:%simpsons = ("father" => "homer", "mother" => "marge", "son" => "bart" +, "daughter" => "lisa"); #deprecated maggie $string = "simpsons"; @array = ("simpsons"); %hash = ("family" => "simpsons"); print("$simpsons{father}\n"); #case1 prints "homer" print("$$string{mother}\n"); #case2 prints "marge" print("$$array[0]{son}\n"); #case3 err print("$$hash{family}{daughter}\n"); #case4 err
But there must be a better way.$ar = $array[0]; print("$$ar{son}\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using other variables as keys to hash
by davorg (Chancellor) on Sep 12, 2001 at 15:10 UTC | |
|
Re: using other variables as keys to hash
by MZSanford (Curate) on Sep 12, 2001 at 15:08 UTC | |
by davorg (Chancellor) on Sep 12, 2001 at 15:18 UTC | |
by MZSanford (Curate) on Sep 12, 2001 at 16:27 UTC | |
|
Re: using other variables as keys to hash
by VSarkiss (Monsignor) on Sep 12, 2001 at 19:02 UTC | |
|
Re: using other variables as keys to hash
by runrig (Abbot) on Sep 12, 2001 at 19:46 UTC |