On Tue, Jun 24, 2008 at 11:56:44PM +1000, Voytek Eymont wrote:
> I'm trying to adopt a script to pull data from water tank gaguges, the
> original script had like below to deal with a single gauge:
> 
> ------------------
> while (1) {
>         my $gotit = "";
>         until ("" ne $gotit) {
>                 $gotit = $port->lookfor;       # poll until data ready
>                 sleep 1;                          # polling sample time
>         }
> 
>       $gotit =~ /a(\d+)b\dc(\d+)/;
> -----------------
> I have two gauges, so they output like so:
> 
> ---
> a1566b0c203d1477e0f205g
> where 156.6 is the depth of tank1 in cm, 0 is the temperature sign bit,
> 20.3 is the air temperature at tank 1 in C, etc.
> ---
> I've tried
>         $gotit =~ /a(\d+)b\dc(\d+)d(\d+)e\df(\d+)/;
> and
>         $gotit =~ /a(\d+)b\dc(\d+)d(\d+)e\df(\d+)g/;
> 
> but I'm not getting it

Your regular expressions look like they should work. Here is another way
you can do it:

#!/usr/bin/perl
use strict;
use warnings;

my $s = "a1566b0c203d1477e0f205g";
my %v = ();

while ($s =~ /(\w)(\d+)/g){
     $v{$1} = $2;
}

for my $k (sort keys %v){
     printf "key %s value %d\n", $k, $v{$k};
}


-- 
Norman Gaywood, Computer Systems Officer
University of New England, Armidale, NSW 2351, Australia

[EMAIL PROTECTED]            Phone: +61 (0)2 6773 3337
http://mcs.une.edu.au/~norm    Fax:   +61 (0)2 6773 3312

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to