in reply to Problems with Quantum::Entanglement

A slightly longer answer more or less equivalent to Mr. Muskrat's reply in a somewhat more programmatic way.

Note that the module has "save_state" and "restore_state" methods. So you can do:
my $die = entangle( 1=>1, 1=>2, 1=>3, 1=>4, 1=>5, 1=>6 ); my $save_state = $die->save_state; for (1..5) { print "$die "; $die = $save_state->restore_state; } # print: "2 1 3 2 5" or whatever
And observe that (of course, the "observation" below will be different each time):
#!/usr/bin/perl -w use Quantum::Entanglement; my $die = entangle( 1=>1, 1=>2, 1=>3, 1=>4, 1=>5, 1=>6 ); print "Pre-observation: ".$die->show_states; print "Observation: $die\n"; print "Post-observation: ".$die->show_states; # print: # # Pre-observation: 1|1> 1|2> 1|3> 1|4> 1|5> 1|6> # Observation: 3 # Post-observation: 1|3>
To see how/why the module collapsed the states (besides being philosophically compliant with quantum mechanics), you could use the Aspect module to track call flow:
#!/usr/bin/perl -w use strict; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - use Aspect qw(advice calls returns around) ; my $aspect = advice( calls(qr/^(Quantum|main)::(.*)/), sub { printf "calling -> %s\n", $::thisjp->sub } ); $aspect->enable; # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - use Quantum::Entanglement; sub foo { my $die = entangle( 1=>1, 1=>2, 1=>3, 1=>4, 1=>5, 1=>6 ); print $die ; print "\n" ; } foo(); # print: # # calling -> main::foo # calling -> main::entangle # calling -> Quantum::Entanglement::_new # calling -> Quantum::Entanglement::("" # calling -> Quantum::Entanglement::_normalise # 5 # calling -> Quantum::Entanglement::DESTROY # calling -> Quantum::Entanglement::_rationalise_states # calling -> Quantum::Entanglement::_unravel # foo();
The ("" thing is (I assume) the double-quote operator, which is overloaded by "str_ent" method in the module (which in turn called "_normalise" ). In str_ent, there is a comment that says:
# set all non retained states to zero probability, leave others alone
So, I guess, each time you print $die, double-quote operator will be used, which uses str_end, which always collapses the states.