Hi, I'm extracting some advisories(number of advisory, type of advisory, and time of advisory) from the internet and am going to store them in a database. But the site stores more than just current advisories on the page, so I need to go through them and ensure they are current. The advisory is valid for 2 hours, so I planned on running the script every hour, and if the advisory valid time is within 1 hour of perl's time, then the advisory is current, and I'll store it in the database. This will work for most numbers if the parse number (valid time) is within 100 of the perl time. For instance, 2200 valid time minus a 2100 perl current time would mean the advisory is current and not more than one hour old. The problem is that when I parse the valid time, I just have a number like 0030, so if Perl's valid time is 2330, it would be an absolute difference of 2300 according to the math but only an hour difference in time. Is there a function to subtract zulu times when they are just strings of 4 numbers like I have in my script?
I've attached the code if you have suggestions. I'm fairly new at programming, so sorry if it's a bit jumbled...I'll take any advice you have. Also, if there are any database variables in there...I haven't finished that part of the coding yet so disregard. Thanks for any help!! #!/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; use DBI; print header; print start_html("WindshftObs"); #initialize variables for mysql insert my $q=new CGI; my $zfw="zfw"; my @number=(); my @type=(); my @time=(); my %CWAone =(); my %CWAtwo =(); my %CWAthree =(); #loop through ob data to parse only text from html ob page my @data = CWA($zfw); #find zulu time using Perl built-in function my @TimeZ= gmtime(); print "@TimeZ<br>"; my $Z_hr=$TimeZ[2]; my $Z_min=$TimeZ[1]; my $Z_time="$Z_hr$Z_min"; print "$Z_time<br>"; #loop through CWA text data to extract CWA number, type, and valid time(Z) foreach my $datum (@data) { push @number, $1 if $datum =~ /CWA (\d{1}0\d{1})/| $datum =~ /(\d{3}) +.{5}KT/; push @type, $1 if $datum =~ /(ICE)/ | $datum =~ /(SEV TURB)/ | $datum =~ /(ICING)/ | $datum =~ /(TS)/ | $datum =~ /(CIGS)/;; push @time, $1 if $datum =~ /UNTIL \d{2}(\d{4})/; } print "@number<br>"; print "@type<br>"; print "@time"; #place wind dir and spd in hashes to referenced later with respect to critical airport values %CWAone = ( number=> $number[0], type=> $type[0], time=> $time[0] ); %CWAtwo= ( number=> $number[1], type=> $type[1], time=> $time[1] ); %CWAthree= ( number=> $number[2], type=> $type[2], time=> $time[2] ); #print CWA one foreach my $firstCWA ("number", "type", "time") { print "$CWAone{$firstCWA}=$firstCWA\n" } #print CWA two foreach my $secondCWA ("number", "type", "time") { print "$CWAtwo{$secondCWA}=$secondCWA\n" } #print CWA three foreach my $thirdCWA ("number", "type", "time") { print "$CWAthree{$thirdCWA}=$thirdCWA\n" } #print differences in times between advisories and current perl time my $timediff1= $CWAone{'time'}-$Z_time; my $abstimediff1=abs($timediff1); print "$abstimediff1<br>"; my $timediff2= $CWAtwo{'time'}-$Z_time; my $abstimediff2=abs($timediff2); print "$abstimediff2<br>"; my $timediff3= $CWAthree{'time'}-$Z_time; my $abstimediff3=abs($timediff3); print "$abstimediff3<br>"; #continue to insert values into database if advisory is determined to be current #if ($timediff1>100 and $timediff1<200) { sub CWA { return "Error: No argument sent to Winds" unless @_; my @apt = @_; my @data; foreach my $cwsu (@apt) { my $url = "http://aviationweather.gov/products/cwsu/dynamic/k $cwsu.shtml"; my $content= get($url) or die "Error getting file: $!"; my $p = HTML::TokeParser::Simple->new(\$content) || die "Can't open: $!"; #$p->empty_element_tags(1); # configure its behaviour while (my $token = $p->get_token) { next unless $token->is_text; push @data, $token->as_is; } } return @data; } print end_html; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/