in reply to Need help with binding event in Tk

You have a problem with precedence in this bit of code:
$key eq "year" ? &show($bros->{$data}->[$list]) : $index = 0;
Perl thinks you possibly want to assign zero to the function show(). If that is not what you want, put parenthesis arount the $index = 0 part, or use a more conventional if..then..else construct. I'm not fond of using the ternary ?: operator in a void context myself, so I'd opt for the second option.

Replies are listed 'Best First'.
Re^2: Need help with binding event in Tk
by Popcorn Dave (Abbot) on Jul 24, 2004 at 18:39 UTC
    Okay that's where I am a bit confused. I thought since I'd defined my conditional, if it was true, then the show sub would execute, and if not, then the other set of code would execute. Since the colon is there, shouldn't that have seperated the two conditions?

    There is no emoticon for what I'm feeling now.
      Check perlop. '?:' has higher precedence than '=', so your code is equivalent to:
      ( ($key eq "year") ? &show($bros->{$data}->[$list]) : $index ) = 0;
      And since you didn't want to return any value (not even an lvalue) from the '?:' operator, you would have been better off using a conventional if (...) {...} else {...} construct. Using '?:' in a void context can be confusing to a maintenance programmer.