title: Should we hire someone who writes C in Perl?
body: <p>One of my colleagues recently interviewed some candidates for a job and one said they had very good Perl experience.</p>
  <p>Since my colleague didn't know Perl, he asked me for a critique of some code written (off-site) by that potential hire, so I had a look and told him my concerns (the main one was that it originally had no comments and it's not like we gave them enough time).</p>
  <p>However, the code works so I'm loath to say no-go without some more input. Another concern is that this code basically looks exactly how I'd code it in C. It's been a while since I did Perl (and I didn't do a lot, I'm more a Python bod for quick scripts) but I seem to recall that it was a much more expressive language than what this guy used.</p>
  <p>I'm looking for input from real Perl coders, and suggestions for how it could be improved (and why a Perl coder <em>should</em> know that method of improvement).</p>
  <p>You can also wax lyrical about whether people who write one language in a totally different language should (or shouldn't be hired). I'm interested in your arguments but this question is primarily for a critique of the code.</p>
  <p>The spec was to successfully process a CSV file as follows and output the individual fields:</p>
  <pre><code>User ID,Name , Level,Numeric ID
  pax, Pax Morgan ,admin,0
  gt,&quot;  Turner, George&quot; rubbish,user,1
  ms,&quot;Mark \&quot;X-Men\&quot; Spencer&quot;,&quot;guest user&quot;,2
  ab,, &quot;user&quot;,&quot;3&quot;
  </code></pre>
  <p>The output was to be something like this (the potential hire's code actually output this):</p>
  <pre><code>User ID,Name , Level,Numeric ID:
     [User ID]
     [Name]
     [Level]
     [Numeric ID]
  pax, Pax Morgan ,admin,0:
     [pax]
     [Pax Morgan]
     [admin]
     [0]
  gt,&quot;  Turner, George  &quot; rubbish,user,1:
     [gt]
     [  Turner, George  ]
     [user]
     [1]
  ms,&quot;Mark \&quot;X-Men\&quot; Spencer&quot;,&quot;guest user&quot;,2:
     [ms]
     [Mark &quot;X-Men&quot; Spencer]
     [guest user]
     [2]
  ab,, &quot;user&quot;,&quot;3&quot;:
     [ab]
     []
     [user]
     [3]
  </code></pre>
  <p>Here is the code they submitted:</p>
  <pre><code>#!/usr/bin/perl
  
  # Open file.
  
  open (IN, &quot;qq.in&quot;) || die &quot;Cannot open qq.in&quot;;
  
  # Process every line.
  
  while (&lt;IN&gt;) {
      chomp;
      $line = $_;
      print &quot;$line:\n&quot;;
  
      # Process every field in line.
  
      while ($line ne &quot;&quot;) {
          # Skip spaces and start with empty field.
  
          if (substr ($line,0,1) eq &quot; &quot;) {
              $line = substr ($line,1);
              next;
          }
  
          $field = &quot;&quot;;
          $minlen = 0;
  
          # Detect quoted field or otherwise.
  
          if (substr ($line,0,1) eq &quot;\&quot;&quot;) {
              $line = substr ($line,1);
              $pastquote = 0;
              while ($line ne &quot;&quot;) {
                  # Special handling for quotes (\\ and \&quot;).
  
                  if (length ($line) &gt;= 2) {
                      if (substr ($line,0,2) eq &quot;\\\&quot;&quot;) {
                          $field = $field . &quot;\&quot;&quot;;
                          $line = substr ($line,2);
                          next;
                      }
                      if (substr ($line,0,2) eq &quot;\\\\&quot;) {
                          $field = $field . &quot;\\&quot;;
                          $line = substr ($line,2);
                          next;
                      }
                  }
  
                  # Detect closing quote.
  
                  if (($pastquote == 0) &amp;&amp; (substr ($line,0,1) eq &quot;\&quot;&quot;)) {
                      $pastquote = 1;
                      $line = substr ($line,1);
                      $minlen = length ($field);
                      next;
                  }
  
                  # Only worry about comma if past closing quote.
  
                  if (($pastquote == 1) &amp;&amp; (substr ($line,0,1) eq &quot;,&quot;)) {
                      $line = substr ($line,1);
                      last;
                  }
                  $field = $field . substr ($line,0,1);
                  $line = substr ($line,1);
              }
          } else {
              while ($line ne &quot;&quot;) {
                  if (substr ($line,0,1) eq &quot;,&quot;) {
                      $line = substr ($line,1);
                      last;
                  }
                  if ($pastquote == 0) {
                      $field = $field . substr ($line,0,1);
                  }
                  $line = substr ($line,1);
              }
          }
  
          # Strip trailing space.
  
          while ($field ne &quot;&quot;) {
              if (length ($field) == $minlen) {
                  last;
              }
              if (substr ($field,length ($field)-1,1) eq &quot; &quot;) {
                  $field = substr ($field,0, length ($field)-1);
                  next;
              }
              last;
          }
  
          print &quot;   [$field]\n&quot;;
      }
  }
  close (IN);
  </code></pre>