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

use warnings;
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use LWP::Simple qw(!head);
use HTML::TokeParser::Simple;
use Data::Dumper;

print header;
print start_html("WindshftObs");
my @wnddir = ();
my @times = ();
my $sjc="sjc";
my $sfo="sfo";
my $sql="sql";



#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;
}
print Dumper @wnddir;
print "@wnddir<br>";






sub Winds  {
   return "Error: No argument sent to Winds" unless @_;
   my @apt = @_;
   my @data;

   foreach my $icao (@apt)  {
      my $url = "http://www.wrh.noaa.gov/mesowest/getobext.php?
wfo=&sid=K$icao&num=3&raw=3&dbn=m&banner=off";
      my $content= get($url) or die "Error getting file: $!";
      my $p = HTML::TokeParser::Simple->new(\$content) || die "Can't
open: $!";



      while (my $token = $p->get_token) {
         next unless $token->is_text;
         push @data, $token->as_is;
      }

   }
return @data;
}

print end_html;

And here's my results:
$VAR1 = undef; $VAR2 = undef; $VAR3 = undef; $VAR4 = '280'; $VAR5 =
'280'; $VAR6 = '340'; $VAR7 = undef; $VAR8 = undef; $VAR9 = undef;
$VAR10 = undef; $VAR11 = '330'; $VAR12 = '330'; $VAR13 = '340'; $VAR14
= undef; 280 280 340 330 330 340

Thanks for your time and any explanations you can give...
Shad


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


Reply via email to