Created
          June 24, 2012 14:07 
        
      - 
      
- 
        Save davestevens/2983346 to your computer and use it in GitHub Desktop. 
    Attempt to display all combinations of data set
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/perl | |
| use strict; | |
| use Data::Dumper; | |
| my @b = (['a','b'],['c','d'],['e','f']); | |
| my @all; | |
| my @single; | |
| &rec(0, \@all, \@single, @b); | |
| print Dumper(@all); | |
| # pass depth, reference to return array, reference to single storage array and data to recurse over | |
| sub rec { | |
| my @data = @_; | |
| my $d = shift(@data); | |
| my $aP = shift(@data); | |
| my $sP = shift(@data); | |
| for(my $i=0;$i<@{$data[$d]};$i++) { | |
| $$sP[$d] = $data[$d][$i]; | |
| if($d == $#data) { | |
| push(@$aP, [@$sP]); | |
| } | |
| else { | |
| &rec(($d+1), $aP, $sP, @data); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment