pwagyi has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks!
Let's say I have an array of object. and also assume that there are some attributes (attr1, attr2, ...attrn) in each object.
I would like to have function/class that can count over any attributes' values. e.g if object is person, and person has attributes, sex ('Male','Female'), ethnic ('a','b','c',...), occupation ('programmer','hacker',...).
If I want to find count# on sex =>But in some cases, I would also need to group,count( array_of_objects, 'sex') => returns ( 'Male' => 45 #male count, 'Female' => 54)
How could I have generic function/class to group and count over collection?count(array, ['sex','occupation']) => ( 'Male' => ( 'programmer' => 10, 'blah' => 34), 'Female' => ('blah' => 3, 'programmer'=>4)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: SQL like query over iterable in perl (updated x2)
by haukex (Archbishop) on Mar 02, 2017 at 07:25 UTC | |
Re: SQL like query over iterable in perl
by Athanasius (Archbishop) on Mar 02, 2017 at 07:33 UTC | |
Re: SQL like query over iterable in perl
by huck (Prior) on Mar 02, 2017 at 07:45 UTC | |
by haukex (Archbishop) on Mar 02, 2017 at 08:55 UTC | |
by huck (Prior) on Mar 02, 2017 at 09:30 UTC | |
by haukex (Archbishop) on Mar 02, 2017 at 13:06 UTC | |
by pwagyi (Monk) on Mar 04, 2017 at 03:33 UTC |
Back to
Seekers of Perl Wisdom