Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monk,
i want to fetch the elements of array, which contain hashes, using reference. i have written the following code but there are errors. Would you help me with my code.Thank You#!/usr/bin/perl -w use strict; my @arr; my %one; my %sec; my %thr; %one = { 1 => 'mili', 2 => 'brown', 3 => 'kalu' }; %sec = { 'age' => 23, 'eyes' => 'hazel', 'weight' => 128 }; %thr = { 'name' => 'deep', 'roll' => 02, 'class' => 'BI' }; my $one = \%one; my $sec = \%sec; my $thr = \%thr; @arr = ($one, $sec, $thr); my $ref = \@arr; for (my $i = 0; $i < 3; $i++) { my $a = $$ref[$i]; print "$a"; foreach my $x (keys %{$a}) { print $x; } } exit 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array of hashes
by bart (Canon) on Feb 10, 2011 at 12:37 UTC | |
by AnomalousMonk (Archbishop) on Feb 10, 2011 at 21:55 UTC | |
|
Re: array of hashes
by moritz (Cardinal) on Feb 10, 2011 at 10:57 UTC | |
|
Re: array of hashes
by hsinclai (Deacon) on Feb 10, 2011 at 16:59 UTC | |
by AnomalousMonk (Archbishop) on Feb 10, 2011 at 21:41 UTC |