Hello,

I am writing an application which parses information
from National Weather Service warnings.
The top 3 lines of each warning message appear as follows:

WUUS52 KGSP 011455
SVRGSP
NCC045-071-109-SCC021-087-091-011545-
The third line contains a series of state/county codes. If the warning is issued for multiple counties in the same state only the first county in the state has the state abbreviation appended to it. In the above example counties 045, 071 and 109 in North Carolina are under a severe thunderstorm warning. Multiple states and counties are handled as in the example above. The last 6 digits are the expiration time in DDHHMM format.

I am trying to parse the third line and match the intermediate county codes to their parent state i.e 071 and 109 to NC.

Here is a snippet of code that I've written which reads the first and third lines. I've tried a few regexes for the third line but I haven't found a way to reliably add the state abbreviation to the intermediate codes. Right now I just get a list of all the codes like this:

NCC045 071 109 SCC021 087..etc.
I am trying to create:
NCC045 NCC071 NCC109 SCC021...etc.

Thanks for any help!

LINE: while(defined($line=<F>)) {
           chomp $line;
           $count++;
           #first line
           if ($line=~/\w{4}\d{2}\s+\w{4}\s+(\d{6})/) {
                      $issueTime = $1;
                      push @warningInfo, $issueTime;
              }
              #third line
              if ($count==3) {
                  
                      push @warningInfo, split/-/,$line
                      $count=0;
                      next FILE;
              }
              else {next;}
      }
      close F;

In reply to A string parsing question by LordAvatar

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.