in reply to Re^2: all binary combinations
in thread all binary combinations

To understand it, read the man page for glob. Then understand the following:

print "$_\n" for glob "{0,1}"; # 0 1 print "$_\n" for glob "{0,1}{0,1}"; # 00 01 10 11 print "$_\n" for glob "{0,1}{0,1}{0,1}"; # 000 001 010 011 100 101 110 + 111

Then read up on the repetition operator in perlop, and understand:

print "AB" x 1; # AB print "AB" x 2; # ABAB print "AB" x 3; # ABABAB

To use it to create keys in a hash, use something like

use Data::Dumper; my %hash = map { $_ => 1 } glob "{0,1}" x 3; print Dumper \%hash; __END__ $VAR1 = { '011' => 1, '010' => 1, '111' => 1, '000' => 1, '101' => 1, '001' => 1, '100' => 1, '110' => 1 };


Unless I state otherwise, all my code runs with strict and warnings