in reply to Re: Regarding the conditional part of eslif (or if) statement
in thread Regarding the conditional part of eslif (or if) statement

Just looking at your
if ($lec){ #... }
block. As has been suggested replacing all those near indentical elsif blocks with a loop would be better.

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
    Thanks wfsp you showed me the logic I was missing at the time.

    I also thank you for reminding me to cut down on typing.

Re^3: Regarding the conditional part of eslif (or if) statement
by ikegami (Patriarch) on Sep 26, 2010 at 00:38 UTC
    for my $i (0..3){ $cell = $pmilecsquare if $pmis[$i] eq $o; }
    should be the following to be equivalent:
    for my $i (0..3){ if ($pmis[$i] eq $o) { $cell = $pmilecsquare; last; } }
    which can be simplified to
    for (@pmis){ if ($_ eq $o) { $cell = $pmilecsquare; last; } }