[EMAIL PROTECTED] wrote:
I'm using html::tokeparser::simple and will next place desired data
into hashes, but I'm having problems getting to the individual pieces
of data.

After using html::tokeparser::simple, then using a regex and pushing
data into a new array, I can't access individual elements of the
array. Using data dumper, I see several variables that are undefined,
in addition to the 3 digit wind directions that I'm looking to access
individually via $wnddir[2] etc.
My goal is to only have what I'm trying to parse (wind directions of 3
digits each in this case) in my array that I'm pushing to. Here's my
code:

#!/usr//bin/perl

[ SNIP ]

#call sub to loop through ob data and parse wnd direction and time of
#observation
my @data = Winds($sfo, $sjc);

foreach my $datum (@data)  {
   my ($wnds) = $datum =~ (/(\d{3})+\d{2}KT|(\d{3})+\d{2}G\d{2}KT/);
   push @wnddir, $wnds;
   my ($Offtime) = $datum =~ (/\d{2}(\d{2})\d{2}Z/);
   push @times, $Offtime;
}

You are adding data to the array whether or not the pattern matched. Test the pattern and only add data when it matches:
(Also you can trim down that pattern.)


foreach my $datum (@data)  {
   if ( $datum =~ /(\d{3})\d{2}(?:G\d{2})?KT/ ) {
      push @wnddir, $1;
   }
   if ( $datum =~ /\d{2}(\d{2})\d{2}Z/ ) {
      push @times, $1;
   }
}



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to