field (\@GRD, 1, \@GRDF1); field (\@GRD, 2, \@GRDF2); field (\@GRD, 3, \@GRDF3); field (\@GRD, 4, \@GRDF4); field (\@GRD, 5, \@GRDF5); field (\@GRD, 6, \@GRDF6);
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 )):
for (1..6) { field (\@GRD,$_,$GRDF[$_]); }
You are using slices when you mean to be referring to list elements. You wrote:
sub field { my ($cmd, $num, $fld) = @_; $max = $#$fld; for ($i = 0; $i <= $max; $i++) { if (@$cmd[$num] eq @$fld[$i]) {
But what you meant was:
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 ..."};
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)...

Celebrate Intellectual Diversity


In reply to Re: Code review by InfiniteSilence
in thread Code review by mhearse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.