| 1 | package Data::PowerSet::Hash; | ||
| 2 | { | ||
| 3 | 2 | $Data::PowerSet::Hash::VERSION = '0.04'; | |
| 4 | } | ||
| 5 | # ABSTRACT: Power sets of hashes | ||
| 6 | |||
| 7 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use parent 'Exporter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 2 | ▶ | use Data::PowerSet 'powerset'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 2 | our @EXPORT_OK = 'hash_powerset'; | |
| 13 | |||
| 14 | 4 | ▶ | sub hash_powerset { |
|
Subroutine
hash_powerset: called CC=2 SCAR=6.9
Pod
documented
| |||
| 15 | 4 | my %hash = @_; | |
| 16 | 4 | my @pset = (); | |
| 17 | 4 | my $pset = powerset( keys %hash ); | |
| 18 | |||
| 19 | 4 | foreach my $combo ( @{$pset} ) { | |
| 20 | push @pset, { | ||
| 21 | 8 | map +( $_ => $hash{$_} ), @{$combo} | |
| 22 | }; | ||
| 23 | } | ||
| 24 | |||
| 25 | 4 | return @pset; | |
| 26 | } | ||
| 27 | |||
| 28 | 2 | 1; | |
| 29 | |||
| 30 | __END__ | ||