Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: array of hashes

by jandrew (Hermit)
on Dec 10, 2010 at 02:42 UTC ( #876364=note: print w/ replies, xml ) Need Help??


in reply to array of hashes

Both more and less.

use 5.010; use strict; use warnings; my @array = ( { car => "ford", color => "red", pet => "dog", }, { car => "honda", color => "blue", pet => "cat", }, { car => "dodge", color => "orange", pet => "spider", }, ); say return_selected_elements( \@array, 'car', 0, 1 ); sub return_selected_elements { my $AoHref = shift; my $element = shift; my @Instances = @_; return join ", ", (map $AoHref->[$_]->{$element}, @Instances); }

Returns

ford, honda


Comment on Re: array of hashes
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2015-07-28 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (251 votes), past polls