perlcartesian-productbless

Why does Math::Cartesian::Product return blessed objects?


I noticed Math::Cartesian::Product returns an array of blessed objects instead of a simple array of arrays. I couldn't figure out why. I actually need to do some extra work (unbless) to use the results...


Solution

  • One alternative is the module Set::CrossProduct, which will yield ordinary, unblessed array references:

    use Set::CrossProduct;
    my $iter = Set::CrossProduct->new([ \@foo, \@bar ]);
    
    while (my $tuple = $iter->get){
        ...
    }
    

    Or get all tuples at once:

    my @tuples = $iter->combinations;