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.

In reply to Re: Problems with Quantum::Entanglement by chunlou
in thread Problems with Quantum::Entanglement by pernod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.