g_speran has asked for the wisdom of the Perl Monks concerning the following question:
@fruit=(Apple, pear, Bananna, Peach); # Populate Fruit Array $new_fruit="Grapes"; # Next Fruit to be added $fruit{0}=248; # Just a random number $fruit{0}{'fruit'}=@fruit; # Want to assign array to this l +ocation in hash @HoldArray=$fruit{0}{'fruit'}; # Want to assign array at ha +sh location $fruit{0}{'fruit'} to HoldArray array push (@HoldArray,$new_fruit); # Push new_fruit to array $fruit{0}{'fruit'}=@HoldArray; # Want to assign updated fru +it array to this hash location #Print out Total fruit and list fruit print "There are $fruit{0} pieces of fruit. The following is a list of + the fruit \n"; foreach ($fruit{0}{'fruit'}) { print "$_ \n"; } exit; ==== End Script ========= ==== Begin Output ======= There are 248 pieces of fruit. The following is a list of the fruit 2 ==== End Output ======== ==== Expected Output ==== There are 248 pieces of fruit. The following is a list of the fruit Apple pear Bananna Peach Grapes ==== End Expected Output ====
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array in a Hash
by ikegami (Patriarch) on Sep 04, 2009 at 02:16 UTC | |
|
Re: Array in a Hash
by bobf (Monsignor) on Sep 04, 2009 at 02:16 UTC | |
by g_speran (Scribe) on Sep 04, 2009 at 04:42 UTC | |
by NetWallah (Canon) on Sep 04, 2009 at 05:32 UTC | |
|
Re: Array in a Hash
by toolic (Bishop) on Sep 04, 2009 at 02:23 UTC | |
|
Re: Array in a Hash
by Anonymous Monk on Sep 04, 2009 at 02:17 UTC |