Yes, that was it. I'm new to the arrow notation, anonymous subroutines, etc., and I'm afraid I'm still a bit puzzled by this, but adding the second line here in the main body of the script makes things work:

my $pick = genPickerConverted(\%kmer_prob); $pick = $pick -> ();

(Before I had only the first line.) When I talk about my code never entering the return block in the anonymous subroutine, I just mean that I add a pause/block in the debugger I'm using (Komodo) and then step through the code, looking at the contents of the variables as I go. When I'm stepping through within the "genPickerConverted" subroutine, I see all the variables being created as expected, but then when it gets to the anonymous subroutine, it just jumps back to the main body of the script. Then looking in "$pick", it looks empty. However, I guess I should have gotten a clue because in the "type" column, all of my hashes are listed as "HASH", all of my arrays are listed as "ARRAY", and all of my scalars are listed as not having a "type", except for $pick, which has type "CODE", and if I print out pick before the dereference statement with the arrow, I get a memory location, like "CODE(0x7f9af358dcb8)".

So what's going on? Does $pick contain a reference to the anonymous subroutine, and it also remembers what was in my %kmer_prob hash?

Thanks so very much for the help. I really appreciate it, I've learned a lot, and I was truly stuck.

Eric


In reply to Re^12: an algorithm to randomly pick items that are present at different frequencies by efoss
in thread an algorithm to randomly pick items that are present at different frequencies by efoss

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.