title: How can I detect a blank line in Perl?
body: <ul>
  <li><p>How do I check a line ($_ value) is a blank line in Perl? Or another
  good method to check it instead of using $_?</p>
  
  <p>I want to code like this</p>
  
  <p>if ($_ eq '')  # Check current line is a blank line (no any characters)
     {
         $x = 0;
     }</p></li>
  </ul>
  
  <hr>
  
  <p>I updated some code with a question solution below.</p>
  
  <p>My <strong>test.txt</strong> for parsing:</p>
  
  <pre><code>   constant fixup private GemAlarmFileName = &lt;A "C:\\TMP\\ALARM.LOG"&gt;
         vid = 0
         name = ""
         units = ""
  
     constant fixup private GemConfigAlarms = &lt;U1 0&gt;         /*  my Comment  */
         vid = 1
         name = "CONFIGALARMS"
     units = ""
     min = &lt;U1 0&gt;
     max = &lt;U1 2&gt;
     default = &lt;U1 0&gt;
  </code></pre>
  
  <p>My code is below.</p>
  
  <p>That's why I need to initially set $x = 0. I am not sure if it is a normal
     solution or not.</p>
  
  <pre><code>    sub ConstantParseAndPrint
      {
          if (/^$/)   // SOLUTION!
          {
              $x = 0;
          }
  
          if ($x == 0)
          {
              if (/^\s*(constant)\s*(fixup|\/\*fixup\*\/|)\s*(private|)\s*(\w+)\s+=\s+&lt;([a-zA-Z0-9]+)\s+(["']?)([a-zA-Z0-9.:\\]+)\6&gt;\s*(\/\*\s*(.*?)\s*\*\/|)(\r|\n|\s)/)
              {
                  $name1 = $1; # Constant
                  $name2 = $2; # Fixup
                  $name3 = $3; # Private
                  $name4 = $4;
                  $name5 = $5;
                  $name6 = $7;
                  $name7 = $8;
                  # start print
                  if (!$name7 eq '')
                  {
                      print DEST_XML_FILE "&lt;!-- $name7--&gt;\n";
                  }
                  print DEST_XML_FILE  "  &lt;ECID";
                  print DEST_XML_FILE " logicalName=\"$name4\"";
                  print DEST_XML_FILE " valueType=\"$name5\"";
                  print DEST_XML_FILE " value=\"$name6\"";
                  $x = 1;
              }
          }
          elsif ($x == 1)
          {
              if(/\s*vid\s*=\s*(.*?)(\s|\n|\r)/)
              {
                  $nID = $1;
                  print DEST_XML_FILE " vid=\"$nID\"";
                  $x = 2;
              }
          }
              elsif ($x == 2)
          {
              if(/\s*name\s*=\s*(.*?)(\s|\n|\r)/)
              {
                  $nName = $1;
                  print DEST_XML_FILE " name=$nName";
                  $x = 3;
              }
          }
              elsif ($x == 3)
          {
              if (/\s*units\s*=\s*(.*?)(\s|\n|\r)/)
              {
                  $nUnits = $1;
                  print DEST_XML_FILE " units=$nUnits";
                  $x = 4;
              }
          }
          elsif ($x == 4)
          {
              # \s+&lt;([a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)&gt;\
              if (/\s*min\s*=\s+&lt;([a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)&gt;(\s|\n|\r)/)
              {
                  #$nMinName1 = $1;
                  $nMinName2 = $2; # Find the nMin Value
                  #$nMinName3 = $3;
                  #$nMinName4 = $4;
                  print DEST_XML_FILE " min=\"$nMinName2\"";
                  $x = 5;
              }
              else
              {
                  print DEST_XML_FILE  "&gt;&lt;/ECID&gt;\n";
                  $x = 0; # There is no line 4 and line 5
              }
          }
          elsif ($x == 5)
          {
              if (/\s*max\s*=\s+&lt;([a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)&gt;(\s|\n|\r)/)
              {
                  #$nMaxName1 = $1;
                  $nMaxName2 = $2; # Find the nMax Value
                  #$nMaxName3 = $3;
                  #$nMaxName4 = $4;
                  print DEST_XML_FILE " max=\"$nMaxName2\"";
                  $x = 6;
              }
          }
          elsif ($x == 6)
          {
              if (/\s*default\s*=\s+&lt;([a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)&gt;(\s|\n|\r)/)
              {
                  #$nDefault1 = $1;
                  $nDefault2 = $2; # Find the default Value
                  #$nDefault3 = $3;
                  #$nDefault4 = $4;
                  print DEST_XML_FILE " default=\"$nDefault2\"&gt;";
                  print DEST_XML_FILE  "&lt;/ECID&gt;\n";
                  $x = 0;
              }
          }
      }
  </code></pre>