Re: Looking for regex
- From: jkufrovich@xxxxxxxxxxxxx (John Kufrovich)
- Date: Sat, 26 Jan 2008 10:13:28 -0800 (PST)
Chas,
Thanks for the help. I'm not expert but I think your code will output each line.
The output I'm trying to achieve.
--Output--.
h:m:s
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 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 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 03:04:00,43.2,34.1,30.11,North,0,7,12,70,0.00,,,0.00,Wunderground v.1.13,
It should cover up to 23 hrs but get the first reading for that hour.
It will read the file and parse the first temp of each hour. Unfortunately, the weather logger isn't consistent enough to use read/write at the top of the hour. The minute reading will vary.
jk
jk
"Chas. Owens" <chas.owens@xxxxxxxxx> wrote:
On Jan 26, 2008 9:38 AM, John Kufrovich wrote:
Time,TemperatureF,DewpointF,PressureIn,WindDirectionsnip
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,
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 () {
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: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
- Follow-Ups:
- Re: Looking for regex
- From: Gunnar Hjalmarsson
- Re: Looking for regex
- From: Chas. Owens
- Re: Looking for regex
- References:
- Re: Looking for regex
- From: Chas. Owens
- Re: Looking for regex
- Prev by Date: Re: 答复: is there a way to read content from lnk on windows?
- Next by Date: Re: Looking for regex
- Previous by thread: Re: Looking for regex
- Next by thread: Re: Looking for regex
- Index(es):
Relevant Pages
|