Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

To me it looks like you have a scope problem, because your code contains closures and I'm pretty sure that this is not intended. A closure is a subroutine that keeps access to a lexical (my) variable that it uses but that is declared somewhere else. For example, your first bind sub uses the variable $text which is declared in the for loop. In each iteration of the loop, the variable is the same (it's not a new $text) and only its value is changed, so all your bind sub actually will keep access to the same $text, meaning they may potentially (and probably) read the same value when called. To avoid this problem, you can create a new variable in each iteration of the loop, so that it isn't shared:

for my $text ( qw( one two three four five six seven eight nine ten ) +) { my $uniq_text = $text; # Copy ... # Your code, where $uniq_text is a new variable that was never u +sed before, and noone else has access to. }

The other issue I see is $panel and $selectedtext which aren't declared anywhere in your example, so I don't know if they are lexicals (my) or package variables (do you use strict?) but in all cases they are shared among all the bind subs, and again I don't know if this is by design or mistake.

And I'm not sure about why you would define @items outside of your InitializeList sub, I suppose it is because you want to read its content after the call? If that's the case, maybe you can return it from the sub, rather handle the same variable in different places:

sub InitializeList { my @items; # no need to undef it for my $text ( qw( one two three four five six seven eight nine ten +) ) ... return @items; } my @res = InitializeList(); # get the items from that call


In reply to Re: Binding within a sub by Eily
in thread Binding within a sub by jsteng

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2020-11-30 08:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?