@result = map scalar reverse,
glob("{1,2,3,4,5,6,7}{A,B,C,D,E,F,G}"); # CheeseLord
@result=map{$a=$_;map$a.$_,1..7}"A".."G"; # runrig
@result=map$_.1..$_.7,"A".."G"; # tilly
# which translates, in your case, into
@result=map$_.$array1[0]..$_.$array1[$#array1],@array;
Update: extravagant solutions
broquaint complained in the CB that I haven't suggested any solutions based on Tree::DAG_Node. While I invite the curious reader to peek at Variant permutation, I propose here a gratuitously heavy DBI solution. :)
#!/usr/bin/perl -w
use strict;
use DBI;
if (-f "permute") {
unlink "permute"
or die "can't unlink permute file\n"
}
my $dbh = DBI->connect("dbi:SQLite:permute",
"","",{RaiseError=>1, PrintError=> 0 })
or die "Error in connecton ($DBI::errstr)\n";
my @array = ('A'..'G') ;
my @array1 = ( 1 .. 7 );
$dbh->do(qq{CREATE TABLE t1 (a char(1)) })
or die "Error in table creation ($DBI::errstr)\n";
$dbh->do(qq{CREATE TABLE t2 (b char(1)) })
or die "Error in table creation ($DBI::errstr)\n";
$dbh->do("begin");
eval {
my $sth = $dbh->prepare (qq{insert into t1 values (?)});
$sth->execute($_) for @array;
$sth = $dbh->prepare (qq{insert into t2 values (?)});
$sth->execute($_) for @array1;
};
if ($@) {
$dbh->do("rollback");
die "error inserting\n";
}
else {
$dbh->do("commit");
}
my $recs = $dbh->selectall_arrayref(
qq{select a,b from t1,t2 }) # an infamous CROSS JOIN !
or die "error fetching records\n";
my @results;
push @results, join( "", @$_) for @$recs;
print "@results\n";
|