title: Parsing latitude and longitude with perl
body: <p>I have a document here that looks like this:</p>
  
  <hr>
  
  <pre><code>FICN10 CWIS 211446
  ICEBERG BULLETIN FOR THE EAST COAST WATERS ISSUED BY ENVIRONMENT
  CANADA AT 11:00 A.M. EDT TUESDAY 21 OCTOBER 2014 FOR TODAY.
  THE NEXT SCHEDULED BULLETIN WILL BE ISSUED AT 11:00 A.M. WEDNESDAY.
  ICEBERG LIMIT AT 0000 UTC 22 OCT ESTIMATED FROM NEWFOUNDLAND NEAR
  4900N 5350W TO 4830N 4900W TO 5000N 4900W TO 6000N 5830W TO
  6000N 4000W TO 3000N 5000W.
  </code></pre>
  
  <hr>
  
  <p>I am trying to use a perl script in which I can get the coordinates into a csv file that looks like this:</p>
  
  <pre><code>4900N 5350W 
  4830N 4900W
  5000N 4900W
  6000N 5830W
  6000N 4000W
  3000N 5000W
  </code></pre>
  
  <p>I have a snippet of code in which I was trying to do this put I do not get the intended results:</p>
  
  <p>Can you look at the code and see what should be done in order to get all the coordinates from the text file into the above format?</p>
  
  <p>Below is the code:</p>
  
  <pre><code>`rm -f coords.TXT`;
  open FPOUT, "&gt;$outfile" or die "\nERROR: Could create/write $outfile\n\n";
  for ( $ii = 0; $ii &lt; 7; $ii++ ) {
      #if ($ii==5)
      #{
      #   print STDOUT "LINE 1\n";
      #}
      #if ($ii==6)
      #{
      #   print STDOUT "LINE 2\n";
      #}
      @words = split " ", "$inline[$ii]";
      for ( $jj = 0; $jj &lt; (@words); $jj++ ) {
          @char = split "", "$words[$jj]";
          $n = 0;
          for ( $kk = 0; $kk &lt; (@char); $kk++ ) {
              $n = $n + 1;
          }
          if ( $n =~ 5 or $n =~ 6 ) {
              if ( $char[0] =~ /[a-zA-z]/ ) {
  
              } else {
                  if ( $char[4] =~ "W" or $char[4] =~ "E" or $char[4] =~ "N" or $char[4] =~ "S" ) {
                      if ( $n =~ 6 ) {
                          if ( $char[5] =~ "." ) {
                              $words[$jj] =~ s/\.//;
                          }
                      }
                      if ( $char[4] =~ "W" or $char[4] =~ "E" ) {
                          $lon = $words[$jj];
                          print STDOUT "longitude is $lon\n";
                      } elsif ( $char[4] =~ "N" or $char[4] =~ "S" ) {
                          $lat = $words[$jj];
                          print STDOUT "Latitude is $lat\n";
  
                      }
                      print FPOUT "$lat $lon\n";
                  }
  
              }
          }
  
      }
  }
  
  close FPOUT;
  </code></pre>