Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: array of hashes

by hsinclai (Deacon)
on Feb 10, 2011 at 16:59 UTC ( [id://887497]=note: print w/replies, xml ) Need Help??


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'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://887497]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-18 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found