good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: SQL like query over iterable in perl (updated x2)by haukex (Archbishop) |
on Mar 02, 2017 at 07:25 UTC ( [id://1183355]=note: print w/replies, xml ) | Need Help?? |
Sounds to me like foreach (and perhaps map) and hashes will help you:
Update: Personally, I'd prefer the above, but if you really want a generic function, here's one option. Probably not the most efficient solution because it's recursive, I don't think the morning caffeine has fully kicked in yet ;-) Input and output is the same as above. (Update: huck's solution, posted before the below, is the non-recursive variation of this.)
Update 2: In the above, I'm working with hash references instead of objects. If you want to use real objects and method calls, then in the first example, replace { $_->{sex} }{ $_->{occupation} } with { $_->sex }{ $_->occupation }, and in the second example, replace $obj->{ shift @path } with $obj->${\shift @path}.
In Section
Seekers of Perl Wisdom
|
|