in reply to array of hashes

#!/usr/bin/perl -w use strict; my $one = { 1 => 'mili', 2 => 'brown', 3 => 'kalu' }; my $sec = { 'age' => 23, 'eyes' => 'hazel', 'weight' => 128 }; my $thr = { 'name' => 'deep', 'roll' => 02, 'class' => 'BI' }; my @arr = ($one, $sec, $thr); my $ref = \@arr; for (my $i = 0; $i < 3; $i++) { while ( my($k,$v) = each %{$$ref[$i]} ) { print " $k " . '-> ' . $v . $/; } }
There must be a nicer way to lay out the dereferencing, someone anyone?

Replies are listed 'Best First'.
Re^2: array of hashes
by AnomalousMonk (Archbishop) on Feb 10, 2011 at 21:41 UTC
    >perl -wMstrict -le "# as before... ;; my $arrayref = [ $one, $sec, $thr, ]; ;; for my $hashref (@$arrayref) { while (my ($k, $v) = each %$hashref) { print qq{ '$k' -> '$v'}; } } " '1' -> 'mili' '3' -> 'kalu' '2' -> 'brown' 'weight' -> '128' 'eyes' -> 'hazel' 'age' -> '23' 'name' -> 'deep' 'class' -> 'BI' 'roll' -> '2'