Maybe something like:
my $data; my $subnet; my $ip = qr/((?:\d{1,3}\.){3}\d{1,3})/; while(<DATA>){ /subnet\s+$ip\s+netmask\s+$ip/ and $subnet = $1 and $data->{"subnet:$subnet"} = { ip => $1, mask => $2, }; /range\s+$ip\s+$ip/ and $data->{"subnet:$subnet"}{range} = { ip => $1, mask => $2, }; /option\s+routers\s+$ip/ and $data->{"subnet:$subnet"}{routers} = { ip => $1 }; /option\s+domain-name\s+"(\S+)"/ and $data->{"subnet:$subnet"}{'domain-name'} = { 'hostname', $1 }; /option\s+domain-name-servers\s+(.+?)\W*$/ and $data->{"subnet:$subnet"}{'domain-name-servers'} = { 'hostname', [ split /,/, $1 ] }; /option\s+option-222\s+"(\S+)"/ and $data->{"subnet:$subnet"}{'option-222'} = { 'hostname', $1 }; } use Data::Dumper;die Dumper($data); __DATA__ subnet 192.168.125.0 netmask 255.255.255.0 { range 192.168.125.200 192.168.125.250; option routers 192.168.125.10; option domain-name "pillepalle.de"; option domain-name-servers 192.168.125.10, 192.168.101.15; option option-222 "http://pillepalle.de:8080"; } __END__ stdout: $VAR1 = { 'subnet:192.168.125.0' => { 'routers' => { 'ip' => '192.168. +125.10' }, 'ip' => '192.168.125.0', 'domain-name-servers' => { 'host +name' => [ + '192.168.125.10', + ' 192.168.101.15' + ] }, 'domain-name' => { 'hostname' => + 'pillepalle.de' }, 'range' => { 'ip' => '192.168.12 +5.200', 'mask' => '192.168. +125.250' }, 'option-222' => { 'hostname' => +'http://pillepalle.de:8080' }, 'mask' => '255.255.255.0' } };



In reply to Re: getting non-default dhcp option value by sh1tn
in thread getting non-default dhcp option value by morlix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.