in reply to Re: Tk warning using curselection() with ActiveState 5.8.4
in thread Tk warning using curselection() with ActiveState 5.8.4

Nope, that returns the size of the list.
This is what is puzzeling me.
$choices[ $dialogLB->curselection ] #can't use arr ref as index value $choices[ @{ $dialogLB->curselection } ] #index value is size of array $choices[ @$dialogLB->curselection ] # not an array ref $choices[ $$dialogLB->curselection ] # not an scalar ref
I don't really mind doing this in two lines, but I don't understand why this used to work but now doesn't.

Replies are listed 'Best First'.
Re^3: Tk warning using curselection() with ActiveState 5.8.4
by tachyon (Chancellor) on Sep 30, 2004 at 02:55 UTC

    How come this no longer works?

    Because you changed your code and added a wantarray perhaps? You are assigning SCALAR context to the return value of your curselection function by using it as an array index. According to Perl it is returning an array ref. This is not a valid index. In your working example you assign ARRAY context to the function call, then that array is evaluated in SCALAR context in the index. Your issue would occur as you say if you had:

    sub curselection { # # was return @array; return wantarray ? @array : \@array; }

    The @$ and $$ issues relate to their precedence being higher than -> so you need @{$a->blah}

    cheers

    tachyon

      "Because you changed your code and added a wantarray perhaps?"

      No. curselection is a method of Tk::Listbox, not something written by the OP. Your guess is reasonable, but 5.8.4 Tk::Listbox document still claims that curselection return a list, just as 5.8.0 does.

      By the way, the OP has to explain what he was trying to do with that piece of code, the code does look suspicious.

Re^3: Tk warning using curselection() with ActiveState 5.8.4
by Anonymous Monk on Sep 30, 2004 at 11:42 UTC
    Nope, that returns the size of the list.

    The code you give as "your solution":

    @index = $dialogLB->curselection; $what = $choices[@index];
    also uses the size of the returned list as an index.