When you see lots of calls that look very, very similar it is a sign that the code needs to be rewritten for brevity. If you had changed @GRDF to a list of list references (as in @GRDF = ( [G Y], [B], \@TBLB2 ) \@TBLB3 [S U] \@MONEY )):field (\@GRD, 1, \@GRDF1); field (\@GRD, 2, \@GRDF2); field (\@GRD, 3, \@GRDF3); field (\@GRD, 4, \@GRDF4); field (\@GRD, 5, \@GRDF5); field (\@GRD, 6, \@GRDF6);
You are using slices when you mean to be referring to list elements. You wrote:for (1..6) { field (\@GRD,$_,$GRDF[$_]); }
But what you meant was:sub field { my ($cmd, $num, $fld) = @_; $max = $#$fld; for ($i = 0; $i <= $max; $i++) { if (@$cmd[$num] eq @$fld[$i]) {
Because your function is basically looking to see if the element is in the array. There are better, cleaner ways to write this than the above but you were using array references in the function calls so this should be consistent with your original purpose (I think)...my ($cmd, $num, $fld_ref) = @_; my $found = 0; #false if ($cmd->[$num] eq "") {$found = 0} else { for (0..$#$fld_ref){ if ($cmd->[$num] eq $fld->[$_]) {$found = 1}; } } if not ($found) {print "ITEM what-cha-ma-calit is not valid ..."};
Celebrate Intellectual Diversity
In reply to Re: Code review
by InfiniteSilence
in thread Code review
by mhearse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |