Jen Spinney wrote: > Hello. It's obvious that I need to factor the follow code, but I'm > not sure how to go about it syntax wise (I read perldoc perlsyn, but > I'm still not sure of the best way). > > if ($color eq $B_COLOR) > { > $id = $c->createLine > ($x[0], $time1, > $x[1], $time1, > -arrow => 'last'; > -fill => $color, > -activefill => 'black', > -width => 2.0, > -tags => [$direction, $color] > ); > } > else > { > $id = $c->createLine > ($x[0], $time1, > $x[1], $time1, > $x[2], $time2, > $x[3], $time2, > -arrow => 'last', > -fill => $color, > -activefill => 'black', > -width => 2.0, > -tags => [$direction, $color], > ); > } > > The only difference between the blocks is two additional lines > ($x[2]...) in the else block. I mean, I know I could write a > subroutine that I could call inside the parentheses that would return > a string (either empty or containing "$x[2]... depending on the result > of the condition test), but that seems clunky. There seems like there > should be a simpler way. Any thoughts? Thanks for any help! - Jen
It looks like you may want something like this: $id = $c->createLine( $x[0], $time1, $x[1], $time1, $color eq $B_COLOR ? () : ( $x[2], $time2, $x[3], $time2, ), -arrow => 'last', -fill => $color, -activefill => 'black', -width => 2.0, -tags => [$direction, $color], ); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>