in reply to nested reg ex over multiple lines

EDIT: Oops, I should have had that as .* instead of \w+. Fixed. And yes, I missed the fact that your solution was line by line instead of straight regex, holli. Shouldn't have posted a (less pretty!) duplicate, though I did arrive at it independently.

You can go ahead and ding me if you like.

----------------

Line by line processing:

use strict; use warnings; use Data::Dumper; my ($key1, $key2, $val, %hash); while (<DATA>) { if (($key2, $val) = m/(\w+)\((.*)\)/) { if ($key2 =~ /^CAL/) { $key1 = $val; } else { $hash{$key1}{$key2} = $val; } } } print Dumper(\%hash); __DATA__ CALCON(test1) { TYPE(U8) FEATURE(DCOM) NAM(stmin) LABEL(Min seperation time between CFs) MIN(0) MAX(127) UNITS(ms) } CALCON(test2) { TYPE(U16) FEATURE(DCOM) NAM(dcomc_sestmr_timeout) LABEL(DCOM Session Timer Timeout) MIN(0) MAX(65535) UNITS(ms) }

Replies are listed 'Best First'.
Re^2: nested reg ex over multiple lines
by holli (Abbot) on Jun 20, 2005 at 19:10 UTC
    That's basically the same code as mine, just yours misses the values with spaces in them (LABEL).


    holli, /regexed monk/