1
#!/usr/local/bin/perl -w
3
# CONVERT FROM ONE EXTERNAL STRUCTURE TO A
4
# SLIGHTLY DIFFERENT INTERNAL STRUCTURE
6
# LOCALIZED RULEVARS ARE ALWAYS EASIEST WHEN CHANGING STRUCTURES
7
# SEE demo_restructure_painful.pl FOR ANOTHER APPROACH THAT SHOWS WHY
10
use Parse::RecDescent;
15
file: <rulevar: local $file>
19
section: header '{' body '}'
20
{ $file->{$item[1]} = $item[3] }
22
header: 'Domain=' /.+/
24
body: <rulevar: local $body>
30
lineA: /[^\W_]+/ '=' /.+/
31
{ $body->{$item[1]} = $item[3] }
33
lineB: /[^\W_]+/ '_' /[^\W_]+/ '=' /.+/
34
{ $body->{$item[1]}{$item[3]} = $item[5] }
37
my $parser = Parse::RecDescent->new($grammar);
43
next if /^\#/; # Strip comments
47
my $f = $parser->file($text);
56
P1_Address=host1:port1
59
P2_Address=host2:port2