[tpm] Regex question

Liam R E Quin liam at holoweb.net
Fri Oct 19 23:55:48 PDT 2012


On Sat, 2012-10-20 at 01:54 -0400, Chris Jones wrote:
> Thanks Liam, we are getting closer but no cigar just yet:

sorry, should have tested it - I forgot the "x" flag on the regular
expression, that lets you include whitespace and comments.

#!/usr/bin/perl
use strict;
my $inLine = "Kitchen Area 1C Spc zn         2750.     1400.     0.249
1.000";

my @zoneLine = ($inLine =~ m{
        ^(.{25})         # the zone name
         \s*([\d.]+)     # supply flow
         \s+([\d.]+)     # exhaust flow
         \s+([\d.]+)     # fan kw
         \s*([\d.]+)     # minimum flow
         \s*
        $}x);


if (@zoneLine == 5) { # matched OK
     $zoneLine[0] =~ s/\s+$//; # remove trailing whitespace
     print "match: ", join(', ', @zoneLine), "\n";
} else {
     print "unmatched: $inLine\n";
}


-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml



More information about the toronto-pm mailing list