I'm seeking constructive critisism on some code. The whole purpose of this script is to make sure a user enters macro commands correctly. Here is an example of the contents of a file which would be checked:
GRD,G,B,L00,HGT,S,10
Here is the script which does the work. Unfortunately, the system this will run on has only the perl 5.05 executable. No modules are available. Any input would be helpful.

while (<>) { chomp; s/ //g; tr/a-z/A-Z/; } if (/^GRD/) { @GRD = split /,"?|""?/; while (@GRD) { attribs (\@GRD, 6); field (\@GRD, 1, \@GRDF1); field (\@GRD, 2, \@GRDF2); field (\@GRD, 3, \@GRDF3); field (\@GRD, 4, \@GRDF4); field (\@GRD, 5, \@GRDF5); field (\@GRD, 6, \@GRDF6); last; } } elsif (/^\s*$/) { next; } elsif (/^\*/) { next; } else { s/\W.*//; chomp $_; warn "$ARGV ling $.: \"$_\" is not a valid APG command!\n"; } close FH if eof; close ARGV if eof; } sub field { my ($cmd, $num, $fld) = @_; $max = $#$fld; for ($i = 0; $i <= $max; $i++) { if (@$cmd[$num] eq @$fld[$i]) { last; } elsif (@$cmd[$num] eq "") { last; } elsif ($i == $max) { print "$ARGV line $.: \"@$cmd[$num]\" is not valid for @$cmd[ +0] field $ num.\n"; last; } } } sub attribs { my ($cmd, $book) = @_; my $given = $#$cmd; if ($given != $book) { warn "$ARGV line $.: \"@$cmd[0]\" incorrect number of attributes +. There s hould be $book.\n"; } } BEGIN { @GRDF1 = qw(G Y); @GRDF2 = qw(B); @GRDF3 = @TBLB2; @GRDF4 = @TBLB3; @GRDF5 = qw(S U); @GRDF6 = @MONEY; }


In reply to 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.