in reply to Another way to match multi-lines from config.
use Data::Dumper; my ( $key, $value, %hash2 ); while ( <DATA> ) { $key = $value = undef and next; if /^interface /; $key = $1 if /description\s+ ([^\"][^\s]+)/x; $value = $1 if /switchport trunk allowed vlan\s*(.*)/; next unless $key && $value; $hash2{$key} = $value; $key = $value = undef; } print Dumper \%hash2;
Using johngg's test data gives:
$VAR1 = { 'ghi.rst-conf' => '21-26,44,47,51', 'def.uvw-conf' => '12-15,31-38', 'abc.xyz-conf' => '15-17,30,35' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Another way to match multi-lines from config.
by nidhi (Acolyte) on Sep 10, 2007 at 23:09 UTC |