I have a data file:

config system interface edit "dmz" set vdom "root" set ip 192.18.254.1 255.255.254.0 set allowaccess ping fgfm set type physical set alias "Guest-Wlan" next edit "wan2" set vdom "test" set ip 10.4.254.198 255.255.255.252 set allowaccess ping https ssh snmp set type physical set alias "To MON ospf int" next edit "wan1" set vdom "root" set ip 1.1.1.1 255.255.255.252 set allowaccess ping https set type physical set alias "To Internet" next edit "modem" set vdom "root" set mode pppoe set allowaccess fgfm set type physical next edit "ssl.root" set vdom "root" set type tunnel next edit "ssl.MyRealm" set vdom "MyRealm" set type tunnel next edit "internal1" set vdom "root" set ip 10.1.16.3 255.255.255.0 set allowaccess ping https ssh snmp fgfm set type physical set alias "To MON Internal " next edit "internal2" set vdom "MyRealm" set dhcp-relay-service enable set dhcp-relay-ip "192.168.1.1" set ip 192.168.2.1 255.255.254.0 set allowaccess ping https ssh snmp fgfm set type physical set alias "To MINE" next edit "VPN-Dial" set vdom "root" set type tunnel set interface "wan1" next end
I want to be able to parse into say, the "Internal1" section, and slurp up the ip. I have written the following code, but cannot get it to match what I need using multiline and push:
#!/usr/bin/perl -w use Switch; my $num_Args=$#ARGV +1; if ($num_Args !=2) { print "\nUsage: Argument 1 is the filename to parse, Argument 2 is t +he Management Ip address\n"; exit; } my $filename = $ARGV[0]; my $ipaddr= $ARGV[1]; open (my $fh, $filename) or die "Could not open file '$filename' $!\n"; while (my $row = <$fh>) { chomp $row; switch ($row){ #print $row; case /config system interface/ { <>; if (/edit \"internal1\"/) { print "Number was 1\n"; $grabbing=1; } elsif ( /^$/ ) { $grabbing = 0; } if ($grabbing ) { push @grabbed, @_; } } } print @grabbed; }
So by the end it would be nice to have a hash table of interfaces and their ip addresses, or even more simply a bunch of variables: 10.1.16.3 $internal1="10.1.16.3" $wan="10.4.254.198" Etc. I want to compare them to the entered string in @argv, and then do some stuff. Any ideas, or is my 'push' idea totally wrong?
"Two Wheels good, Four wheels bad."

In reply to Grabbing Structured multi line output from a file? by symgryph

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.