in reply to Combinations / permutations... not even sure what this is called

It's very interesting to see various ways of thinking and there is a lot to learn for me.

I thought SQL's cross join will give you what you want. In real world, sometimes values comes from database and if you use cross join in such case, it is very handy.

#!/usr/bin/perl use strict; use warnings; use DBI; my($dbh,$testdb); $testdb='wnjpn.db';#SQLite database path $dbh=DBI->connect("dbi:SQLite:$testdb","","", {AutoCommit=>0,RaiseErro +r=>0}); #populate table while(<DATA>){ $dbh->do($_) or print DBI->errstr; } $dbh->commit; #print with natural join my $r=$dbh->selectall_arrayref( qq( select test_c.v || '-' ||test_s.v || '-' ||test_num.v as v from test_c cross join test_s cross join test_num; )) or die DBI->errstr; #),{ Slice => {} }) or die DBI->errstr; use Data::Dumper; print Dumper $r; $dbh->disconnect; __DATA__ drop table test_c; drop table test_s; drop table test_num; create table test_s ( v text primary key); create table test_c ( v text primary key); create table test_num ( v text primary key); insert into test_c values ( 'red'); insert into test_c values ( 'blue'); insert into test_s values ( 'small'); insert into test_s values ( 'medium'); insert into test_s values ( 'large'); insert into test_num values ( '1'); insert into test_num values ( '2'); insert into test_num values ( '3'); insert into test_num values ( '4');
  • Comment on Re: Combinations / permutations... not even sure what this is called
  • Download Code