I'm seeking constructive critisism on some code.

First, I don't think

while (<>) { chomp; s/ //g; tr/a-z/A-Z/; } if (/^GRD/) {
is doing what you think it is. Ponder the difference between
while ( ... ) { ... } if ( ... ) { ... }
and
while ( ... ) { ... if ( ... ) { .... } }
Next, can you explain what   @GRD = split /,"?|""?/; is supposed to be doing? It leads me to believe that there's more to your data than the sample shows. Is your data a CSV file with quoted values?

And what is   close ARGV if eof; supposed to be doing? Is there a file handle named ARGV that you opened previously? If so, that's the not the right way to test for eof.

Your field routine looks like it was written by someone who speaks C, but who hasn't yet come to terms with Perl, either in terms of control structures or in terms of how to deal with variable names. If I'm reading your intent correctly, it can be collapsed into something like

my @GRD = split /,/; warn "line $.: wrong number of attributes\n" unless @GRD == 6; check($GRD[0], 1, @GRDF1); check($GRD[1], 2, @GRDF2); ... check($GRD[5], 6, @GRDF6); sub check ( my($GRD, $col, $@GRDF) = @_; return if grep { $GRD eq $_ } @GRDF; print "line $.: \"$GRD\" is invalid in column $col\n"; }
There are are better ways of doing this, but this gives you an example to chew on that illustrates some of the aspects of Perl that C programmers can gain great advantage in learning.


In reply to Re: Code review by dws
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.