I am new to Regex and keep getting this error... First the code:
#!/usr/bin/perl -w my $pkgdoc = <<'EOD'; #/**------------------------------------------------------------------ +- # @ file TC-parcer.pl # This script parses the fetched TC data from Dr. landsea's TC # reclassification project. # # @since 03/18/2008 # @usage TC-parcer.pl txtfile.txt # date: June 25, 2008 #--------------------------------------------------------------------* +/ EOD # ## Pull arguments from the command line # use strict; use warnings; use Getopt::Long; if (@ARGV <1) { # if arg < 1 then pr +int the pckdoc print $pkgdoc; exit -1; } my $txtfile = shift; # pulling arguments # ## Open text file with Dr. Landsea's data if not stop the program # open (DATA, $txtfile)||die "cannot open $txtfile for reading"; # ## Gather data from the title line which looks like: # ### 00065 08/16/1851 M=12 4 SNBR= 4 NOT NAMED XING=1 SSS=3 # while (<DATA>) { my ($CardNo, $MMDD, $YY, $TotalNo, $SNRB, $StormNo, $Name, $XING, $S +SS)= m{^(\d+)\s+ (\d\d/\d\d) /(\d+)\s+ M=(\d+)\s+ (\d+)\s+ SNBR=\s*(\ +d+)\s+ (.+) \s* XING=(\d+)\s+ SSS=(d+) \s* $}x; $Name =~ s/NOT NAMED/NONAME/; # replacing NOT NAME +D with NONAME $TotalNo = $TotalNo * 4; print "$MMDD $TotalNo $Name$StormNo-$YY $XING $SSS $CardNo\n"; last if $SSS !~ /[0-5]/; # skip to data lines } # ## Gather important data of the center of each storm # ### 00070 08/16*134 480 40 0*137 495 40 0*140 510 50 + 0*144 528 50 0* # while (<DATA>) { my ($CardNo, $MMDD, $Type, $LAT1, $LON1, $Vmax1, $Pmin1, $TET1, $LAT +2, $LON2, $Vmax2, $Pmin2, $TET2, $LAT3, $LON3, $Vmax3, $Pmin3, $TET3, + $LAT4, $LON4, $Vmax4, $Pmin4, $TET4) = m{^(\d+)\s+ (\d\d/\d\d)\s+ (. ++) (\d\d\d)\s+ (\d\d\d)\s+ (\d+)\s+ (\d+)\s+ (.+) (\d\d\d)\s+ (\d\d\d +)\s+ (\d+)\s+ (\d+)\s+ (.+) (\d\d\d)\s+ (\d\d\d)\s+ (\d+)\s+ (\d+)\s+ + (.+) (\d\d\d)\s+ (\d\d\d)\s+ (\d+)\s+ (\d+)\s+ (.+) \s* $}x; if ($TET1 = '*') {$TET1 = 'T';} if ($TET2 = '*') { $TET2 = 'T';} if ($TET3 = '*') { $TET3 = 'T';} if ($TET4 = '*') { $TET4 = 'T';} print "$MMDD 0000 $LAT1 $LON1 $Vmax1 $Pmin1 $TET1\n $MMDD 0600 $LAT2 + $LON2 $Vmax2 $Pmin2 $TET2\n $MMDD 1200 $LAT3 $LON3 $Vmax3 $Pmin3 $TE +T3\n $MMDD 1800 $LAT4 $LON4 $Vmax4 $Pmin4 $TET4\n"; last if $TET4 !~ m/T|E$/; # end this storm's t +rack } close (DATA);
My error message shows:
Use of uninitialized value in concatenation (.) or string at TCparcer. +pl line 78, <DATA> line 14.
and so on ... The data in question to parse is:
00065 08/16/1851 M=12 4 SNBR= 4 NOT NAMED XING=1 SSS=3 00070 08/16*134 480 40 0*137 495 40 0*140 510 50 0*144 528 + 50 0* 00075 08/17*149 546 60 0*154 565 60 0*159 585 70 0*161 604 + 70 0* 00080 08/18*166 625 80 0*169 641 80 0*172 660 90 0*176 676 + 90 0* 00085 08/19*180 693 90 0*184 711 70 0*189 726 60 0*194 743 + 60 0* 00090 08/20*199 759 70 0*205 776 70 0*212 790 70 0*219 804 + 70 0* 00095 08/21*226 814 60 0*232 825 60 0*239 836 70 0*244 843 + 70 0* 00100 08/22*250 849 80 0*256 855 80 0*262 860 90 0*268 863 + 90 0* 00105 08/23*274 865 100 0*280 866 100 0*285 866 100 0*296 861 + 100 0* 00110 08/24*307 851 90 0*316 841 70 0*325 830 60 0*334 814 + 50 0* 00115 08/25*340 800 40 0*348 786 40 0*358 770 40 0*368 751 + 40 0* 00120 08/26*378 736 40 0*389 718 40 0*400 700 40 0*413 668 + 40 0* 00125 08/27*428 633 40 0*445 602 40 0*464 572 40 0*485 542 + 40 0* 00130 HRAFL3IGA1
Plus I would like to run this program on a text file that contains more than one storm on it, in the similar format as above (just more of them continuously on one file). So I was thinking of doing a while loop, but what will be the basis for it to return true in order to continue to redo the title parcing and the data parcing. Not to mention skip the last line which could start with any 5 numbers and any letters (last if?)

In reply to New to Regex and need help by MKevin

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.