in reply to Re: Regarding the conditional part of eslif (or if) statement
in thread Regarding the conditional part of eslif (or if) statement
block. As has been suggested replacing all those near indentical elsif blocks with a loop would be better.if ($lec){ #... }
If you have a default, set it at the begining and avoid an else block.
For within a small scope it also worth using a temp var to hold the value of a var with a long name that will be used many times. This also uses a temp "holding" var ($cell) so that the write method only appears once.
This approach helps eliminate a lot of repitition which can be confusing and hard to maintain. And it cuts down typing. :-)
# give ourselves a short name # in a short scope my $o = $outdate{$key1}; if ($lec and $lec = $o) { # set the default my $cell = $lecsquare; if ($tacho eq $o) { $cell = $tacholecsquare; } else { for my $i (0..3){ $cell = $pmilecsquare if $pmis[$i] eq $o; } } $worksheet1->write($r, $y, "L", $cell); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regarding the conditional part of eslif (or if) statement
by ramjamman (Sexton) on Sep 25, 2010 at 23:53 UTC | |
|
Re^3: Regarding the conditional part of eslif (or if) statement
by ikegami (Patriarch) on Sep 26, 2010 at 00:38 UTC |