Note that on that particular kind of feed, you *can* have three digits on occasion.

How would you go about allowing for the third digit if and only if it exists?

I had the first regex, but I'm not sure where the allowance for the third digit would come in, or how to allow for a random series of digits that can contain two or three at any given time.

--j

Note: I mean my little jab to go privately for fun. I didn't mean to come off sounding quite so douchey. Apologies all around.


On Jan 26, 2008, at 11:04 AM, Chas. Owens wrote:

On Jan 26, 2008 9:38 AM, John Kufrovich <[EMAIL PROTECTED]> wrote:
Time,TemperatureF,DewpointF,PressureIn,WindDirection
2007-01-23 00:01:00,43.3,34.9,30.14,North, 359,7,8,72,0.00,,,0.00,Wunderground v.1.13,
snip
What I am trying to accomplish is pull the first temp for each hour. I have tried various combinations of regex and none seem to correctly on hr:min:sec.
snip

Out of "2007-01-23 01:11:00,42.9," you want 01 and  42.9.  The first
thing to notice is that the first time a space shows up in the data is
right before what we want.  This is wonderful.  It will act as our
first anchor point.  We then need to capture the next two characters
(the hour) then anything up to (and including) the next match a comma,
and finally capture anything up to the next comma. So, now we need to
translate that into a regex.

our anchor point: / /
capture two characters: /(..)/
match anything up to (and including) the next comma: /.*?,/
capture anything up to (but not including) the next comma /(.*?),/

Put it all together and you get: / (..).*?,(.*?),/.

You also mentioned that you only want the first temp for each hour.
Whenever you hear the words unique, first, or last, your brain should
scream "hash!":

#! /usr/bin/perl

use strict;
use warnings;

my %seen;
while (<DATA>) {
        my ($hour, $temp) = / (..).*?,(.*?),/;
        print "temp was $temp at $hour\n" unless $seen{$hour}++;
}

__DATA__
2007-01-23 00:01:00,43.3,34.9,30.14,North, 359,7,8,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 00:06:00,43.2,34.8,30.14,North, 354,11,11,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 00:12:00,43.2,34.8,30.14,North, 1,6,9,72,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 01:11:00,42.9,34.8,30.13,North, 1,5,6,73,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 01:17:00,42.9,34.8,30.12,NNW, 346,3,7,73,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 01:23:00,43.1,35.0,30.12,North, 359,5,11,73,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 02:14:00,43.2,34.1,30.10,North, 0,16,16,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 02:19:00,43.2,34.1,30.09,North, 0,6,13,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 02:24:00,43.2,33.7,30.09,North, 349,8,14,69,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 03:04:00,43.2,34.1,30.11,North, 0,7,12,70,0.00,,,0.00,Wunderground
v.1.13,
2007-01-23 03:09:00,43.2,34.1,30.11,North, 0,10,17,70,0.00,,,0.00,Wunderground
v.1.13,

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




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


Reply via email to