[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Cartesian Cross-Products



  Hello,

  what about that :

#!/usr/bin/perl -w

use Data::Dumper ;

sub cartesian {
  my @res = map {[$_]} @{shift()} ;
  while (@_){
    @res = map {$a=$_;map {[@$_,$a]} @res} @{shift()} ;
  }
  @res ;
}


@a = qw(Hello World) ;
@b = 1..4 ;
@c = qw(F W P);

@d = cartesian(\@a,\@b,\@c) ;

print Dumper \@d ;

  Cheers,

  Etienne

ps : YOu may want to reverse @_ .

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe